<template>
  <qui-page :data-qui-theme="theme" :header="false">
    <view class="post-box" v-if="loadStatus">
      <view class="post-box__title" v-if="type === 1">
        <input v-if="type === 1" class="post-box__title-input" type="text" v-model="postTitle" :focus="type === 1"
          :placeholder="i18n.t('discuzq.post.pleaseEnterAPostTitle')" />
      </view>
      <view class="post-box__titles" v-if="type === 5">
        <qui-cell-item v-if="type === 5" :title="i18n.t('discuzq.post.askedUsers')" slot-right arrow
          @tap="changeAvatar">
          <qui-avatar class="my-profile__avatar" :user="{ avatarUrl: userImage, username: beUserName }"
            style="margin-right: 20rpx;" />
          <view class="username">{{ beUserName }}</view>
        </qui-cell-item>
      </view>

      <!-- #ifdef MP-WEIXIN -->
      <view class="post-box__hd">
        <view class="post-box__hd-l">
          <qui-icon class="post-box__hd-l__icon" name="icon-expression" size="40"
            :color="emojiShow ? '#1878F3' : '#777'" @click="emojiclick"></qui-icon>
          <qui-icon class="post-box__hd-l__icon" name="icon-call" size="40" color="#777" @click="callClick"></qui-icon>
          <qui-icon class="post-box__hd-l__icon" name="icon-wei" size="40" color="#777" @click="topicPage"></qui-icon>
        </view>
        <text class="post-box__hd-r" v-if="type !== 5">
          {{
            textAreaValue.length != textAreaLength
              ? i18n.t('discuzq.post.note', { num: textAreaLength - textAreaValue.length })
              : i18n.t('discuzq.post.exceed', { num: textAreaValue.length - textAreaLength })
          }}
        </text>
        <text class="post-box__hd-r" v-if="type === 5">
          {{
            textAreaValue.length != textAreaLength
              ? i18n.t('discuzq.post.note', { num: textAreaLength - textAreaValue.length })
              : i18n.t('discuzq.post.exceed', { num: textAreaValue.length - textAreaLength })
          }}
        </text>
      </view>
      <view class="emoji-bd" v-show="emojiShow">
        <qui-emoji position="absolute" top="20rpx" border-radius="10rpx" @click="getEmojiClick"></qui-emoji>
      </view>
      <view class="post-box__con">
        <textarea id="textarea" ref="textarea" class="post-box__con-text" :placeholder="
            type !== 5
              ? i18n.t('discuzq.post.placeholder')
              : i18n.t('discuzq.post.placeholderQuestion')
          " placeholder-class="textarea-placeholder" v-model="textAreaValue" auto-height="true"
          :show-confirm-bar="barStatus" :adjust-position="true" cursor-spacing="30" cursor="cursor" :maxlength="49999"
          :focus="type !== 1" v-show="textShow" @blur="contBlur" @focus="focusEvent"></textarea>
        <view class="post-box__con-text post-box__con-text--static" v-show="!textShow">
          <text class="text-cover">{{ textAreaValue }}</text>
        </view>
        <view class="markdown-box" v-if="markdownShow">
          <view>
            <qui-icon name="icon-bold" size="30" class="qui-icon" @click="toolBarClick('bold')"></qui-icon>
          </view>
          <view>
            <qui-icon name="icon-title" size="30" class="qui-icon" @click="toolBarClick('title')"></qui-icon>
          </view>
          <view>
            <qui-icon name="icon-italic" size="30" class="qui-icon" @click="toolBarClick('italic')"></qui-icon>
          </view>
          <view>
            <qui-icon name="icon-quote" size="30" class="qui-icon" @click="toolBarClick('quote')"></qui-icon>
          </view>
          <view>
            <qui-icon name="icon-code" size="30" class="qui-icon" @click="toolBarClick('code')"></qui-icon>
          </view>
          <view>
            <qui-icon name="icon-link" size="30" class="qui-icon" @click="toolBarClick('link')"></qui-icon>
          </view>
          <view>
            <qui-icon name="icon-strikethrough" size="30" class="qui-icon" @click="toolBarClick('strikethrough')">
            </qui-icon>
          </view>
        </view>
      </view>
      <!-- #endif -->
      <!-- 开头表情包部分 -->
      <!-- #ifdef H5 ||APP-PLUS -->
      <view v-if="type !== 1">
        <view class="post-box__hd">
          <!-- #ifndef H5 || MP-WEIXIN || APP-PLUS -->
          <view class="post-box__hd-l">
            <qui-icon class="post-box__hd-l__icon" name="icon-expression" size="40"
              :color="emojiShow ? '#1878F3' : '#777'" @click="emojiclick"></qui-icon>
            <qui-icon class="post-box__hd-l__icon" name="icon-call" size="40" color="#777" @click="callClick">
            </qui-icon>
            <qui-icon class="post-box__hd-l__icon" name="icon-wei" size="40" color="#777" @click="topicPage"></qui-icon>
          </view>
          <!-- #endif -->
          <!-- #ifdef H5|| MP-WEIXIN || APP-PLUS -->
          <view class="post-box__hd-l">
            <qui-icon class="post-box__hd-l__icon" name="icon-expression" size="34"
              :color="emojiShow ? '#EA3D5A' : '#999999'" @click="emojiclick"></qui-icon>
            <qui-icon class="post-box__hd-l__icon" name="icon-call" size="40" color="#777" @click="callClick">
            </qui-icon>
            <qui-icon class="post-box__hd-l__icon" name="icon-wei" size="34" color="#999999" @click="topicPage">
            </qui-icon>
          </view>
          <!-- #endif -->
          <text class="post-box__hd-r" v-if="type !== 5">
            {{
          textAreaValue.length &lt;= textAreaLength
          ? i18n.t('discuzq.post.note', { num: textAreaLength - textAreaValue.length })
          : i18n.t('discuzq.post.exceed', { num: textAreaValue.length - textAreaLength })
            }}
          </text>
          <text class="post-box__hd-r" v-if="type === 5">
            {{
          textAreaValue.length &lt;= textAreaLength
          ? i18n.t('discuzq.post.note', { num: textAnswerLength - textAreaValue.length })
          : i18n.t('discuzq.post.exceed', { num: textAreaValue.length - textAnswerLength })
            }}
          </text>
        </view>
        <view class="emoji-bd" v-show="emojiShow">
          <qui-emoji position="absolute" top="20rpx" border-radius="10rpx" @click="getEmojiClick"></qui-emoji>
        </view>
        <!-- 文本框输入部分 -->
        <view class="post-box__con">
          <textarea id="textarea" ref="textarea" class="post-box__con-text" :placeholder="
              type !== 5
                ? i18n.t('discuzq.post.placeholder')
                : i18n.t('discuzq.post.placeholderQuestion')
            " placeholder-class="textarea-placeholder" v-model="textAreaValue" auto-height="true"
            :show-confirm-bar="barStatus" :adjust-position="true" cursor-spacing="30" cursor="cursor" :maxlength="49999"
            :focus="type !== 1" v-show="textShow" @blur="contBlur" @focus="focusEvent"></textarea>
          <view class="post-box__con-text post-box__con-text--static" v-show="!textShow">
            <text class="text-cover">{{ textAreaValue }}</text>
          </view>
          <view class="markdown-box" v-if="markdownShow">
            <view>
              <qui-icon name="icon-bold" size="30" class="qui-icon" @click="toolBarClick('bold')"></qui-icon>
            </view>
            <view>
              <qui-icon name="icon-title" size="30" class="qui-icon" @click="toolBarClick('title')"></qui-icon>
            </view>
            <view>
              <qui-icon name="icon-italic" size="30" class="qui-icon" @click="toolBarClick('italic')"></qui-icon>
            </view>
            <view>
              <qui-icon name="icon-quote" size="30" class="qui-icon" @click="toolBarClick('quote')"></qui-icon>
            </view>
            <view>
              <qui-icon name="icon-code" size="30" class="qui-icon" @click="toolBarClick('code')"></qui-icon>
            </view>
            <view>
              <qui-icon name="icon-link" size="30" class="qui-icon" @click="toolBarClick('link')"></qui-icon>
            </view>
            <view>
              <qui-icon name="icon-strikethrough" size="30" class="qui-icon" @click="toolBarClick('strikethrough')">
              </qui-icon>
            </view>
          </view>
        </view>
        <!-- 文本框输入部分结束 -->
      </view>
      <!-- 表情包部分结束 -->
      <view v-else>
        <!-- 大长输入框 -->

        <view ref="vditor">
          <view class="post-box__hd">

            <view class="post-box__hd-l">
              <qui-icon class="post-box__hd-l__icon" name="icon-expression" size="34"
                :color="emojiShow ? '#EA3D5A' : '#999999'" @click="emojiclick"></qui-icon>
              <qui-icon class="post-box__hd-l__icon" name="icon-call" size="40" color="#777" @click="callClick">
              </qui-icon>
              <qui-icon class="post-box__hd-l__icon" name="icon-wei" size="34" color="#999999" @click="topicPage">
              </qui-icon>
            </view>

            <text class="post-box__hd-r" v-if="type !== 5">
              {{
            textAreaValue.length &lt;= textAreaLength
            ? i18n.t('discuzq.post.note', { num: textAreaLength - textAreaValue.length })
            : i18n.t('discuzq.post.exceed', { num: textAreaValue.length - textAreaLength })
              }}
            </text>
            <text class="post-box__hd-r" v-if="type === 5">
              {{
            textAreaValue.length &lt;= textAreaLength
            ? i18n.t('discuzq.post.note', { num: textAnswerLength - textAreaValue.length })
            : i18n.t('discuzq.post.exceed', { num: textAreaValue.length - textAnswerLength })
              }}
            </text>
          </view>
          <view class="emoji-bd" v-show="emojiShow">
            <qui-emoji position="absolute" top="20rpx" border-radius="10rpx" @click="getEmojiClick"></qui-emoji>
          </view>
          <!-- 文本框输入部分 -->
          <view class="post-box__con">
            <textarea id="textarea" ref="textarea" class="post-box__con-text" :placeholder="
                type !== 5
                  ? i18n.t('discuzq.post.placeholder')
                  : i18n.t('discuzq.post.placeholderQuestion')
              " placeholder-class="textarea-placeholder" v-model="textAreaValue" auto-height="true"
              :show-confirm-bar="barStatus" :adjust-position="true" cursor-spacing="30" cursor="cursor"
              :maxlength="49999" :focus="type !== 1" v-show="textShow" @blur="contBlur" @focus="focusEvent"></textarea>
            <view class="post-box__con-text post-box__con-text--static" v-show="!textShow">
              <text class="text-cover">{{ textAreaValue }}</text>
            </view>

          </view>
          <!-- 文本框输入部分结束 -->
        </view>

        <!--   大长输入框结束 -->
      </view>
      <!-- #endif -->

      <!-- #ifdef H5 || MP-WEIXIN || APP-PLUS -->
      <!-- 仅在红版环境下编译 -->
      <qui-uploader :url="`${url}api/attachments`" :form-data="formData" :file-preview="filePreview" name="file"
        :async-clear="true" ref="upload" v-if="type === 1 || type === 3 || type === 5" @change="uploadChange"
        @clear="uploadClear" @uploadClick="uploadClick"></qui-uploader>
      <!-- #endif -->
      <qui-upload-file :url="`${url}api/attachments`" ref="uploadFiles" :header="header"
        :attachment-list="attachmentList" :max-length="5"
        :file-format="forums.set_attach && forums.set_attach.support_file_ext"
        :file-size="forums.set_attach && forums.set_attach.support_max_size"
        v-show="type === 1 && type !== 5 && forums.other && forums.other.can_upload_attachments"
        @deleteItem="deleteFile"></qui-upload-file>
      <qui-upload-video v-if="type === 2" ref="uploadVideo" :type-status="operating" :url="url"
        :video-before-list="videoBeforeList" :controls="controlsStatus" :choose-type="chooseType" @videoDel="videoDel">
      </qui-upload-video>
      <view class="post-box__audio" v-if="type === 4">
        <qui-upload-audio ref="uploadAudio" :audio-before-list="audioBeforeList" @change="uploadAudioChange"
          @audioDel="audioDel"></qui-upload-audio>
      </view>
      <qui-cell-item :title="i18n.t('discuzq.post.lookPay')" :addon="showPayType" arrow
        v-if="type === 1 && forums.other && forums.other.can_create_thread_paid && ioshide" @click="lookPay">
      </qui-cell-item>
      <view v-if="type === 1">
        <qui-cell-item :class="price > 0 ? 'cell-item-right-text' : ''" :title="i18n.t('discuzq.post.paymentAmount')"
          :addon="showPrice" arrow v-if="
            type !== 0 &&
              showHidden &&
              forums.paycenter &&
              forums.paycenter.wxpay_close &&
              payType !== 0 &&
              forums.other.can_create_thread_paid &&
              ioshide
          " @click="cellClick('pay')"></qui-cell-item>
      </view>
      <view v-else-if="
          type !== 0 && type !== 5 && type !== 6 && forums.other.can_create_thread_paid && ioshide
        ">
        <qui-cell-item :class="price > 0 ? 'cell-item-right-text' : ''" :title="
            type === 4
              ? i18n.t('discuzq.post.payByListeningToAudio')
              : i18n.t('discuzq.post.paymentAmount')
          " :addon="showPrice" arrow v-if="
            type !== 0 &&
              showHidden &&
              forums.paycenter.wxpay_close &&
              forums.other.can_create_thread_paid &&
              ioshide
          " @click="cellClick('pay')"></qui-cell-item>
      </view>
      <view v-if="type === 6">
        <view class="post-box__good" v-if="isShowGoods && type === 6 && dataGoodInfo">
          <view>
            <image class="post-box__good__image" lazy-load :src="dataGoodInfo.imagePath" />
          </view>
          <view class="post-box__good__info" >
            <view class="post-box__good__title">{{ dataGoodInfo.title }}</view>
            <view class="post-box__good__ft" :style="{
                justifyContent: dataGoodInfoPrice !== '' ? 'space-between' : 'flex-end',
              }">
              <view class="post-box__good__price" v-if="dataGoodInfoPrice !== ''">
                ￥{{ dataGoodInfoPrice }}元
              </view>
              <qui-icon name="icon-delete" size="26" @click="deleteGoods"></qui-icon>
            </view>
          </view>
        </view>

        <view class="post-box__space" v-else @click="addGoods">
          <qui-icon name="icon-add" size="26"></qui-icon>
        </view>
      </view>
      <!-- 匿名提问 -->
      <view class="uni-list-cell uni-list-cell-pd" v-if="anonymity_show && operating !== 'edit'">
        <view class="uni-list-cell-db">{{ i18n.t('discuzq.post.anonymity') }}</view>
        <!-- #ifndef H5 || MP-WEIXIN || APP-PLUS -->
        <u-switch @change="changeCheck" v-model="checked" active-color="#1E78F3"></u-switch>
        <!-- #endif -->
        <!-- #ifdef H5 || MP-WEIXIN || APP-PLUS -->
        <u-switch @change="changeCheck" v-model="checked" active-color="#EA3D5A"></u-switch>
        <!-- #endif -->
      </view>
      <!-- 是否允许围观 -->
      <view class="uni-list-cell uni-list-cell-pd" v-if="type === 5 && forums.other && forums.other.can_be_onlooker">
        <view class="uni-list-cell-db">
          <view class="">
            {{ `${i18n.t('discuzq.post.otherPay')}${forums.set_site.site_onlooker_price}元` }}
          </view>
          <view class="watchpay">
            {{
              parseInt(haveDate) === 0
                ? ''
                : `${i18n.t('discuzq.post.youHaveTo')}
              ${haveDate}${i18n.t('discuzq.post.yuan')},`
            }}
            {{
              parseInt(answerIsDate) === 0
                ? ''
                : `${i18n.t('discuzq.post.theAnswerIs')}
              ${answerIsDate}${i18n.t('discuzq.post.yuan')},`
            }}
            {{
              parseInt(platformDate) === 0
                ? ''
                : `${i18n.t('discuzq.post.platform')}
              ${platformDate}${i18n.t('discuzq.post.yuan')}`
            }}
          </view>
        </view>
        <!-- #ifndef H5 || MP-WEIXIN || APP-PLUS -->
        <u-switch @change="changeCheck" v-model="watchChecked" active-color="#1E78F3"></u-switch>
        <!-- #endif -->
        <!-- #ifdef H5 || MP-WEIXIN || APP-PLUS -->
        <u-switch @change="changeCheck" v-model="watchChecked" active-color="#EA3D5A"></u-switch>
        <!-- #endif -->
      </view>

      <qui-cell-item :title="i18n.t('discuzq.post.freeWordCount')"
        :addon="i18n.t('discuzq.post.word', { num: percentagedisplay })" v-if="
          price > 0 &&
            type !== 3 &&
            type !== 2 &&
            type !== 0 &&
            type !== 4 &&
            type !== 5 &&
            payType !== 1 &&
            payType !== 0
        " arrow @click="cellClick('word')"></qui-cell-item>
      <view class="post-box__position" v-if="redshow">
        <!-- 红包功能 -->
        <qui-cell-item v-if="operating !== 'edit' || (operating === 'edit' && is_red_packet)" arrow :slot-left="true"
          @tap="skipred_packet()">
          <view>
            <text v-if="!is_red_packet">添加红包</text>
            <text v-else class="redshowstyle">
              <text>{{ sumtype }}红包</text>
              <text style="margin-right: 10rpx;margin-left: 10rpx;">/</text>
              {{ sumtype === '随机' ? '总金额' : '每个' }}
              <text style="margin-right: 10rpx;"></text>
              <text class="redshowstyle_redmargin">{{ showmoney }}</text>
              元
              <text style="margin-right: 10rpx;margin-left: 10rpx;">/</text>
              <text class="redshowstyle_redelse">{{ number }}</text>
              个
            </text>
          </view>
        </qui-cell-item>
        <qui-icon name="icon-close1" size="32" color="#ccc" @tap="clearPacket"
          v-if="is_red_packet && operating !== 'edit'"></qui-icon>
      </view>
      <!-- 红包功能结束 -->
      <view class="post-box__position" v-if="forums.lbs && forums.lbs.lbs">
        <!-- 添加位置开始 -->
        <qui-cell-item arrow :slot-left="true" @click="choosePosition" v-if="geographical_location">
          <view>
            <!-- #ifndef H5 || MP-WEIXIN || APP-PLUS -->
            <qui-icon name="icon-weizhi" size="35" color="#777"></qui-icon>
            <!-- #endif -->
            <text>
              {{
                currentPosition && currentPosition.location
                  ? currentPosition.location
                  : i18n.t('discuzq.post.addPosition')
              }}
            </text>
          </view>
        </qui-cell-item>
        <qui-icon name="icon-close1" size="32" color="#ccc" @tap="clearPosition"
          v-if="currentPosition && currentPosition.location"></qui-icon>
      </view>
      <!-- 添加位置结束 -->

      <view class="post-box__ft">
        <text class="post-box__ft-tit">版块名称：{{thread_name}}</text>
        <!-- 循环分类功能 -->

        <!-- 循环分类功能结束 -->
        <!-- 发布按钮功能 -->

        <!-- #ifdef H5 || MP-WEIXIN || APP-PLUS -->
        <view class="bottom_button">
          <qui-button class="button" v-if="type !== 5" :loading="postLoading" type="primary" size="minpink"
            id="TencentCaptcha" :data-appid="(forums.qcloud && forums.qcloud.qcloud_captcha_app_id) || ''"
            @click="postClick" :disabled="textAreaValue.length > textAreaLength">
            {{ i18n.t('discuzq.post.post') }}
          </qui-button>
          <qui-button class="button" v-if="type === 5" :loading="postLoading" type="primary" size="minpink"
            id="TencentCaptcha" :data-appid="(forums.qcloud && forums.qcloud.qcloud_captcha_app_id) || ''"
            @click="postAnswerClick" :disabled="textAreaValue.length > textAreaLength">
            {{ i18n.t('discuzq.post.post') }}
          </qui-button>
          <qui-button :loading="postLoading" type="primary" size="minpink" id="TencentCaptcha"
            :data-appid="(forums.qcloud && forums.qcloud.qcloud_captcha_app_id) || ''"
            :disabled="textAreaValue.length > textAreaLength" @tap="toDraftsing">
            保存草稿箱
          </qui-button>
        </view>
        <!-- #endif -->
        <!-- 发布按钮功能结束 -->
        <!-- 问答的支付部分 -->
        <!-- #ifndef H5 || MP-WEIXIN|| APP-PLUS -->
        <qui-button class="button" v-if="type === 5 && forums.other && forums.other.can_create_thread_paid"
          :loading="postLoading" type="primary" size="large" id="TencentCaptcha"
          :data-appid="(forums.qcloud && forums.qcloud.qcloud_captcha_app_id) || ''" @click="postAnswerClick"
          :disabled="textAreaValue.length > textAreaLength">
          {{ i18n.t('discuzq.post.nextPay') }}
        </qui-button>
        <qui-button class="button" v-if="type === 5 && forums.other && forums.other.can_create_thread_paid"
          :loading="postLoading" type="primary" size="large" id="TencentCaptcha"
          :data-appid="(forums.qcloud && forums.qcloud.qcloud_captcha_app_id) || ''"
          :disabled="textAreaValue.length > textAreaLength" @tap="toDraftsing">
          保存草稿箱
        </qui-button>
        <!-- #endif -->
        <!-- 问答的支付部分结束 -->
      </view>
      <!--支付组件-->
      <view v-if="payShowStatus">
        <qui-pay ref="payShow" :pay-type="payTypeText" :money="priceAsk" :wallet-status="user.canWalletPay"
          :balance="Number(user.walletBalance)" :walletBalance="Number(walletBalance)" :pay-password="pwdVal"
          :pay-type-data="payTypeData" :to-name="beUserName" @paysureShow="paysureShow" @onInput="onInput"
          @radioChange="radioChange"></qui-pay>
        <!-- 红包支付组件 -->
        <qui-pay ref="payShowtwo" pay-type="红包支付" :money="money" :wallet-status="user.canWalletPay"
          :balance="Number(user.walletBalance)" :walletBalance="Number(walletBalance)" :pay-password="pwdVal"
          :pay-type-data="payTypeData" :to-name="beUserName" @paysureShow="paysureShow" @onInput="onInput"
          @radioChange="radioChange"></qui-pay>
      </view>
      <uni-popup ref="lookPayPopup" type="bottom">
        <view class="popup-share">
          <view class="pay-type" @click="choicePayType(0)">
            {{ i18n.t('discuzq.post.TheContentAndTheAccessoriesIsFree') }}
          </view>
          <view class="pay-type" v-if="type === 1 && canUploadAttachment" @click="choicePayType(1)">
            {{ i18n.t('discuzq.post.TheContentIsFreeAndTheAccessoriesArePaid') }}
          </view>
          <view class="pay-type" @click="choicePayType(2)">
            {{ i18n.t('discuzq.post.TheContentAndTheAccessoriesIsPaid') }}
          </view>
          <view class="popup-share-content-space"></view>
          <text class="popup-share-btn" @click="cancelLookPay()">
            {{ i18n.t('discuzq.post.cancel') }}
          </text>
        </view>
      </uni-popup>
      <uni-popup ref="popupBtm" type="bottom">
        <view class="popup-share">
          <view class="popup-share-content">
            <text class="popup-title" v-if="type !== 5">
              {{
                setType === 'pay'
                  ? i18n.t('discuzq.post.selectToViewPaymentAmount')
                  : i18n.t('discuzq.post.selectToViewFreeWordCount')
              }}
            </text>
            <text class="popup-title" v-if="setType === 'pay' && type === 5">
              {{ i18n.t('discuzq.post.supportTheAuthorToContinueToCreate') }}
              <!-- ~打赏,  支持回答者继续创作 -->
            </text>
            <view class="popup-content-btn" v-if="setType === 'pay'">
              <qui-button class="popup-btn" v-for="(item, index) in payNum" :key="index" :type="
                  payNumCheck.length > 0 && payNumCheck[0].name === item.name ? 'primary' : 'post'
                " plain size="post" @click="moneyClick(index)">
                {{ item.name }}
              </qui-button>
            </view>
            <!-- 设置免费的字数百分比 -->
            <view class="popup-content-btn" v-if="setType === 'word'">
              <qui-button class="popup-btn" v-for="(item, index) in freepercentage" :key="index"
                :type="freewords.length > 0 && freewords[0].name === item.name ? 'primary' : 'post'" plain size="post"
                @click="percentageClick(index)">
                {{ item.name }}
              </qui-button>
            </view>
          </view>
          <view class="popup-share-content-space"></view>
          <text class="popup-share-btn" @click="cancel()">
            {{ i18n.t('discuzq.post.cancel') }}
          </text>
        </view>
      </uni-popup>
      <view v-if="popupStatus">
        <uni-popup ref="popup" type="center">
          <view class="popup-dialog">
            <view class="popup-dialog__top">
              <text>
                {{ i18n.t('discuzq.post.payMoney') }}
                <!-- ~输入查看付费金额 -->
                <!-- ~输入查看字数 -->
              </text>
            </view>
            <view class="popup-dialog__cont">
              <qui-icon class="popup-dialog__cont-rmb" name="icon-rmb" size="40" v-if="setType === 'pay'"></qui-icon>
              <text class="popup-dialog__cont-rmb" v-else>
                {{ i18n.t('discuzq.post.word', { num: '' }) }}
                <!-- ~个字 -->
              </text>
              <input class="popup-dialog__cont-input" v-if="setType === 'pay'" v-model="inputPrice" type="digit"
                placeholder="0.0" :maxlength="maxLength" :focus="setType === 'pay'" @input="checkNum" />
              <input class="popup-dialog__cont-input" v-else v-model="inputWord" type="digit" placeholder="0"
                :maxlength="5" :focus="setType === 'word'" />
            </view>
            <view class="popup-dialog__ft">
              <button class="popup-btn--close" @click="diaLogClose">
                {{ i18n.t('discuzq.close') }}
              </button>
              <button class="popup-btn--ok" v-if="setType === 'pay'"
                :class="inputPrice > 0 ? 'popup-btn--ok--blue' : ''" :disabled="inputPrice === ''" @click="diaLogOk">
                {{ i18n.t('discuzq.ok') }}
              </button>
              <button class="popup-btn--ok" v-else :class="inputWord > 0 ? 'popup-btn--ok--blue' : ''"
                :disabled="inputWord === ''" @click="diaLogOk">
                {{ i18n.t('discuzq.ok') }}
              </button>
            </view>
          </view>
        </uni-popup>
      </view>
      <uni-popup ref="deletePopup" type="center">
        <uni-popup-dialog type="warn" :content="deleteTip" :before-close="true" @close="handleClickCancel"
          @confirm="handleClickOk"></uni-popup-dialog>
      </uni-popup>
      <uni-popup ref="wechatPopup" type="center">
        <uni-popup-dialog type="warn" :content="wechatTip" :before-close="true" @close="handleWechatClickCancel"
          @confirm="handleWechatClickOk"></uni-popup-dialog>
      </uni-popup>
      <qui-toast ref="toast"></qui-toast>
      <qui-loading-cover v-if="coverLoading" mask-zindex="111"></qui-loading-cover>
    </view>
  </qui-page>
</template>

<script>
  import {
    mapState,
    mapMutations
  } from 'vuex'; // vuex里的仓库和更改的办法
  import {
    DISCUZ_REQUEST_HOST
  } from '@/common/const'; // 这个会等于路由里的host，会根据版本变化，几乎可以说会等于主路由
  // import VodUploader from '@/common/cos-wx-sdk-v5.1';
  import forums from '@/mixin/forums'; // 拿本地缓存数据的方法
  import user from '@/mixin/user'; // 不知道干嘛的，好像是重复发送请求的
  import loginModule from '@/mixin/loginModule'; // 用来各种小程序登录请求的
  // #ifdef  H5 || APP-PLUS
  import tcaptchs from '@/utils/tcaptcha'; // 1200多行没备注，神仙，看不懂，应该是组件封

  // #endif

  // #ifdef H5
  import appCommonH from '@/utils/commonHelper'; // 判断设备类型的方法
  // #endif
  import uniPopupDialog from '@/components/uni-popup/uni-popup-dialog'; // 弹出的对话框
  import apiRequest from '../api/new-api';
  // #ifdef MP-WEIXIN
  import getTemplates from '@/mixin/getTemplate';
  // #endif
  // 小程序与h5支付setInterval
  let payWechat = null;
  const payPhone = null;
  export default {
    name: 'Post',
    components: {
      uniPopupDialog
    }, // 对话框设置为组件引用
    mixins: [
      // 混入方法使之内部可以直接使用
      forums, // 计算属性里添加一个请求数据的方法
      user, // 不知道干嘛的，好像是重复发送请求的
      loginModule, // 用来各种小程序登录请求的
      // #ifdef H5
      tcaptchs, // 1200多行没备注，神仙，看不懂，应该是组件封装的方法

      appCommonH, // 判断设备类型的方法
      // #endif
// #ifdef MP-WEIXIN
      getTemplates
      // #endif
    ],
    data() {
      return {

        lowestPrice: 0, // 最低打赏价格
        redbagplay: true, // 是否允许编辑红包，如果是管理员从编辑进来的，不允许修改红包
        geographical_location: false, // 地理位置是否显示
        anonymity_show: false, // 匿名是否显示
        redshow: false, // 红包是否显示
        // redlongshow: true, // 红包长文帖的时候是否显示
        save: false, // 帖子保存，防止上一个保存还没成功就发下一个保存了
        SecondaryClassification: '', // 二级分类参数
        titlexune: '已添加0个标题',
        secondallcategories: [], // 二级分类
        is_onlookers: false, // 是否允许他人围观
        two_categoryId: '', // 二级分类选中
        situation_categoryId: '', // 定义一个全局的id，用来发送请求
        is_red_packet: '', // 文字帖类型 0-普通帖 1-红包贴
        showmoney: '', // 展示单个金额多少钱
        rule: '', // 红包贴模式 0-定额 1-随机
        money: '', // 红包金额
        number: '', //  红包数量
        condition: '', // 红包获得条件 0-回复 1-集赞
        likenum: '', // 集赞数
        sumtype: '', // 显示是红包是随机还是定额
        timer1: null, // 准备启动自动保存
        timer2: null, // 自动保存
        cansavedraft: true, // 要不要开启草稿箱自动保存
        currentId: '', // 当前发布帖子的ID
        // 以上是后面加的
        vditor: this.$refs.vditor,
        navTitle: '发布', // 导航栏标题
        loadStatus: '',
        textAreaValue: '', // 输入框内容
        markdownShow: false, // 是否显示markdown菜单
        barStatus: false, // 是否显示输入框获取焦点时完成的那一栏
        textAreaLength: 5000, // 输入框可输入字
        textAnswerLength: 49999, // 问答输入框可输入字
        postTitle: '', // 标题
        checkClassData: [],
        type: 0, // 帖子类型
        price: 0, // 付费金额
        priceAsk: 0, // 提问价格
        pwdVal: '', // 提问价格的支付密码
        browser: 0, // 是不是浏览器
        inputPrice: '', // 付费金额输入框
        maxLength: 7, // 输入框长度
        inputWord: '', // 查看字数输入框
        operating: '', // 编辑或发布类型
        emojiShow: false, // 表情是否显示
        textShow: true, // 文本域是否显示
        header: {}, // 图片请求头部
        formData: {}, // 图片请求data
        captcha: null, // 腾讯云验证码实例
        captcha_ticket: '', // 腾讯云验证码返回票据
        captcha_rand_str: '', // 腾讯云验证码返回随机字符串
        userImage: '', // 被提问用户的头像
        beUserName: '', // 被提问用户的用户名
        checked: false, // 是否匿名
        watchChecked: false, // 他人围观
        watchShow: false, // 是否显示他人围观
        payShowStatus: true, // 是否显示支付
        haveDate: 0, // 你得
        answerIsDate: 0, // 回答者得
        platformDate: 0, // 平台得
        askingPrice: true, // 显示提问价格
        payNum: [
          // 弹出的红包金额的渲染数组
          {
            name: this.i18n.t('discuzq.post.TheContentAndTheAccessoriesIsFree'),
            pay: 0,
          },
          {
            name: '￥2',
            pay: 2,
          },
          {
            name: '￥5',
            pay: 5,
          },
          {
            name: '￥10',
            pay: 10,
          },
          {
            name: '￥20',
            pay: 20,
          },
          {
            name: '￥50',
            pay: 50,
          },
          {
            name: '￥88',
            pay: 88,
          },
          {
            name: '￥128',
            pay: 128,
          },
          {
            name: this.i18n.t('discuzq.post.customize'),
            pay: 0,
          },
        ], // 付费金额
        payNumCheck: [
          // 付费金额选中
          {
            name: '',
            pay: 0,
          },
        ], // 付费金额选中
        freepercentage: [
          // 免费字数的百分比的数组
          {
            name: '0%',
            pay: 0,
          },
          {
            name: '10%',
            pay: 0.1,
          },
          {
            name: '30%',
            pay: 0.3,
          },
          {
            name: '50%',
            pay: 0.5,
          },
          {
            name: '70%',
            pay: 0.7,
          },
          {
            name: '100%',
            pay: 1,
          },
        ],
        freewords: [], // 免费字数选中
        percentagedisplay: '0%',
        uploadFile: [], // 图片上传列表
        cursor: 0, // 内容输入框光标未知
        wordCountCheck: [{
          name: this.i18n.t('discuzq.post.word', {
            num: 0
          }),
          num: 0,
        }, ], // 查看字数选中
        word: 0, // 可查看字数
        setType: 'pay', // 金额或查看字
        controlsStatus: false, // 是否显示默认播放控件
        videoBeforeList: [], // 视频上传列表
        audioBeforeList: [], // 语音上传列表
        fullscreenStatus: false, // 视频全屏状态
        videoName: '', // 视频名称
        percent: 0, // 视频上传进度
        // videoPercent: 0, // 视频上传进度，用来控制进度条
        fileId: '', // 视频ID
        url: '', // 视频url
        postLoading: false, // 发布按钮loading状态
        allCategories: [], // 所有分类
        categoryIndex: '', // 分类下标
        categoryId: '', // 一级分类id
        threadId: '', // 编辑时主题id
        firstPostId: '', // 编辑时帖子id
        postDetails: {}, // 编辑时帖子详情
        filePreview: [], // 服务器上传
        uploadStatus: true, // 图片上传状态
        showHidden: true, // 付费金额的显示隐藏
        ticket: '',
        randstr: '',
        captchaResult: {},
        attachmentList: [], // 附件列表
        signatureVal: '',
        deleteType: '', // 删除类型 0为图片，1为附件，2为视频
        deleteId: '', // 当前点击要删除的图片Id
        deleteIndex: '', // 当前点击要删除的图片index
        deleteTip: '确定删除吗？', // 删除提示
        wechatTip: this.i18n.t('discuzq.wechatBind'), // 微信绑定提示
        currentPosition: {},
        watchMoeny: '1', // 他人付费需付费多少元
        beAskId: '', // 被提问人ID
        payTypeText: '', // 支付提问价格文案
        orderSn: '', // 提问支付订单号
        coverLoading: false, // 提问支付遮罩层
        payStatus: false, // 订单支付状态
        walletBalance: '0:0',
        payTypeData: [
          // 微信支付和钱包支付的渲染数据
          {
            name: '我的钱包(商城)',
            icon: 'icon-wxPay',
            color: '#09bb07',
            value: '0',
          },
          {
            name: '钱包支付(社区)',
            icon: 'icon-walletPay',
            color: '#1878f3',
            value: '1',
          },
        ], // 支付方式
        chooseType: 1, // 视频是从首页上传的还是从发布页上传的
        payType: 0, //  查看付费的方式，  0均免费， 1内容免费，附件付费，  2内容和附件都付费
        showPayType: '', // 选择的支付方式
        ioshide: false, // ios下付费隐藏
        isShowGoods: false,
        dataGoodInfo: {},
        dataGoodInfoPrice: 0, // 商品价格
        goodsId: '', // 商品ID
        categoryid: 0,
        categoryindex: 0,
        postShow: false,
        popupStatus: false, // 这是自定义金额或者自定义字数弹框显示状态
        canUploadAttachment: false, // 用户上传附件权限
        Submiting:false,  //防止重复提交
      };
    },
    computed: {
      // 计算属性
      ...mapState({
        getAtMemberData: state => state.atMember.atMemberData,
      }),
      thread_name() {
        const value = uni.getStorageSync('thread_name');
        return value;
      },
      thread_id() {
        return uni.getStorageSync('thread_id');
      },
      showPrice() {
        let pay = '';
        // let pay = this.i18n.t('discuzq.post.free');
        if (this.type === 1) {
          pay = this.i18n.t('discuzq.post.pleaseChoice');
        } else {
          pay = this.i18n.t('discuzq.post.free');
        }

        if (this.price <= 0) {
          if (this.type === 1) {
            pay = this.i18n.t('discuzq.post.pleaseChoice');
          } else {
            pay = this.i18n.t('discuzq.post.free');
          }
          // pay = this.i18n.t('discuzq.post.free');
        } else {
          pay = `￥${this.price + this.i18n.t('discuzq.post.yuan')}`;
        }
        return pay;
      },
      showAskPrice() {
        let payAsk = this.i18n.t('discuzq.post.free');
        if (this.priceAsk <= 0) {
          payAsk = this.i18n.t('discuzq.post.free');
        } else {
          payAsk = `￥${this.priceAsk + this.i18n.t('discuzq.post.yuan')}`;
        }
        return payAsk;
      },
      currentLoginId() {
        const userId = this.$store.getters['session/get']('userId');
        return parseInt(userId, 10);
      },
      // goodInfo() {
      //   const data = this.$store.getters['session/get']('good');
      //   // this.dataGoodInfo = data;
      //   if (data && data._jv) {
      //     return data;
      //   }
      // return {};
      // },
    },
    beforeDestroy() {
      this.save = true;
      clearInterval(this.timer1);
      this.timer1 = null;
      clearInterval(this.timer2);
      this.timer2 = null;
    },
    updated() {
      // 数据更新后

      this.red_bagshow();
      this.geographical_location_show();
      if (this.forums && this.type === 5) {
        this.platformDate = (
          this.forums.set_site.site_onlooker_price *
          (this.forums.set_site.site_master_scale / 10)
        ).toFixed(2);
        this.haveDate = ((this.forums.set_site.site_onlooker_price - this.platformDate) / 2).toFixed(
          2,
        );
        this.answerIsDate = (
          this.forums.set_site.site_onlooker_price -
          this.platformDate -
          this.haveDate
        ).toFixed(2);
      }
      // #ifdef H5
      this.$nextTick(() => {
        if (this.$refs.textarea) {
          this.$refs.textarea.$refs.textarea.style.overflowY = 'auto';
          this.$refs.textarea.$refs.textarea.style.paddingRight = '10px';
        }
      });
      // #endif
      uni.$off('uploadVideoOver');
      uni.$on('uploadVideoOver', data => {
        // 这是计算周期里获取到的上传后的数据
        this.percent = 1;
        if (data.doneResult) {
          this.fileId = data.doneResult.fileId;
        } else if (data.result) {
          this.fileId = data.result.fileId;
        }
        this.videoBeforeList.push({
          path: data.uploadVideoRes.tempFilePath,
        });
      });
    },
    methods: {
      //查询钱包
      getData() {
        let self = this;
        self.loading = true;
        self._get(
          'balance.log/index', {},
          function(res) {
            self.walletBalance = res.data.balance;
          }
        );
      },
      // 用来随时调用的方法
      // 红包是否显示的方法
      red_bagshow() {
        if (this.forums) {
          if (this.type === 0 && this.forums.other.can_create_thread_red_packet) {
            this.redshow = true;
          }
          if (this.type === 1 && this.forums.other.can_create_thread_long_red_packet) {
            this.redshow = true;
          }
        }
      },
      // 位置和匿名是否显示
      geographical_location_show() {

        if (this.type === 0 && this.forums.other.can_create_thread_position) {
          this.geographical_location = true;
        }
        if (this.type === 1 && this.forums.other.can_create_thread_long_position) {
          this.geographical_location = true;
        }
        if (this.type === 2 && this.forums.other.can_create_thread_video_position) {
          this.geographical_location = true;
        }
        if (this.type === 3 && this.forums.other.can_create_thread_image_position) {
          this.geographical_location = true;
        }
        if (this.type === 4 && this.forums.other.can_create_thread_audio_position) {
          this.geographical_location = true;
        }
        if (this.type === 5 && this.forums.other.can_create_thread_question_position) {
          this.geographical_location = true;
        }

        if (this.type === 6 && this.forums.other.can_create_thread_goods_position) {
          this.geographical_location = true;
        }
        // 匿名是否显示
        switch (this.type) {
          case 0:
            this.anonymity_show = this.forums.other.can_create_thread_anonymous;
            break;
          case 1:
            this.anonymity_show = this.forums.other.can_create_thread_long_anonymous;
            break;
          case 2:
            this.anonymity_show = this.forums.other.can_create_thread_video_anonymous;
            break;
          case 3:
            this.anonymity_show = this.forums.other.can_create_thread_image_anonymous;
            break;
          case 4:
            this.anonymity_show = this.forums.other.can_create_thread_audio_anonymous;
            break;
          case 5:
            this.anonymity_show = this.forums.other.can_create_thread_question_anonymous;
            break;
          default:
            this.anonymity_show = this.forums.other.can_create_thread_goods_anonymous;
        }
      },
      // 手动保存草稿箱
      toDraftsing() {
        if (this.redbagplay === false) return;


        this.save = true;
        clearInterval(this.timer2);
        this.timer2 = null;
        // 手动保存成功
        // const params = {
        //   _jv: {
        //     type: 'threads',
        //     relationships: {
        //       category: {
        //         data: {
        //           type: 'categories',
        //           id: this.two_categoryId || this.categoryId,
        //         },
        //       },
        //     },
        //     links: {
        //       self:
        //         'threads?include=user,category,firstPost,firstPost.images,firstPost.postGoods,question,question.beUser,question.beUser.groups,question.images',
        //     },
        //   },
        //   content: this.textAreaValue,
        //   type: this.type,
        //   price: this.price,
        //   free_words: this.word,
        //   captcha_ticket: this.ticket,
        //   captcha_rand_str: this.randstr,
        //   is_anonymous: this.checked,
        //   is_draft: 1,
        //   is_old_draft: 0,
        //   id: this.currentId,
        //   is_red_packet: this.is_red_packet,
        //   redPacket: {
        //     rule: +this.rule,
        //     money: +this.money,
        //     number: +this.number,
        //     condition: +this.condition,
        //     likenum: +this.likenum,
        //   },
        // };
        const paramsNum = {
          categoriesId: Number(this.thread_id),
          content: this.textAreaValue,
          type: this.type,
          isAnonymous: this.checked ? 1 : 0,
          price: this.price,
          freeWords: this.word,
          id: this.currentId,
          isDraft: 1,
          isOldDraft: 0,
          captchaTicket: this.ticket,
          captchaRandStr: this.randstr,
          redPacket: {
            rule: +this.rule,
            money: +this.money,
            number: +this.number,
            condition: +this.condition,
            likenum: +this.likenum,
            orderId: this.orderSn,
            orderPrice: 0,
          },
        };
        // #ifdef H5|| APP-PLUS
        if (this.vditor && this.type === 1) {
          // params.content = this.vditor
          //   .getValue()
          //   .replace(/blob:/g, '')
          //   .replace(/\n\n/g, '\n\n\n');
          paramsNum.content = this.vditor
            .getValue()
            .replace(/blob:/g, '')
            .replace(/\n\n/g, '\n\n\n');
        }
        // #endif
        // if (this.payType === 1) {
        //   params.attachment_price = this.price;
        //   params.price = '';
        // } else if (this.payType === 0) {
        //   params.attachment_price = '';
        //   params.price = this.price;
        // }
        if (this.payType === 1) {
          paramsNum.attachmentPrice = this.price;
          paramsNum.price = '';
        } else if (this.payType === 0) {
          paramsNum.attachmentPrice = '';
          paramsNum.price = this.price;
        }
        // const { currentPosition } = this;
        // params.longitude = currentPosition.longitude || '';
        // params.latitude = currentPosition.latitude || '';
        // params.location = currentPosition.location || '';
        // params.address = currentPosition.address || '';
        const currentPositions = this.currentPosition;
        if (currentPositions) {
          paramsNum.longitude = Number(currentPositions.longitude) || '';
          paramsNum.latitude = Number(currentPositions.latitude) || '';
          paramsNum.location = currentPositions.location || '';
          paramsNum.address = currentPositions.address || '';
        }
        const postPromise = new Promise((resolve, reject) => {
          switch (this.type) {
            case 0:
              resolve();
              break;
            case 1: {
              // params.title = this.postTitle;
              // params._jv.relationships.attachments = {
              //   data: this.addImg().data.concat(this.addFile().data),
              // };
              paramsNum.title = this.postTitle;
              const num = this.addImg().data.concat(this.addFile().data);
              paramsNum.attachments = [];
              num.forEach(item => {
                paramsNum.attachments.push({
                  id: Number(item.id),
                  type: item.type
                });
              });
              resolve();
              break;
            }
            case 2:
              // params.file_id = this.fileId;
              // params.file_name = this.videoName;
              paramsNum.fileId = this.fileId;
              paramsNum.fileName = this.videoName;
              resolve();
              break;
            case 3: {
              const numImg = this.addImg().data;
              paramsNum.attachments = [];
              numImg.forEach(item => {
                paramsNum.attachments.push({
                  id: Number(item.id),
                  type: item.type
                });
              });
              // params._jv.relationships.attachments = this.addImg();
              resolve();
              break;
            }
            case 4:
              paramsNum.fileId = this.audioBeforeList[0].id;
              paramsNum.fileName = this.audioBeforeList[0].fileName;
              // params.file_id = this.audioBeforeList[0].id;
              // params.file_name = this.audioBeforeList[0].fileName;
              resolve();
              break;
            case 5: {
              const askNum = this.addImg().data;
              const askQuestion = this.addQuestion().data;
              paramsNum.attachments = [];
              paramsNum.question = {};
              askNum.forEach(item => {
                paramsNum.attachments.push({
                  id: Number(item.id),
                  type: item.type
                });
              });
              if (askQuestion) {
                paramsNum.question.type = askQuestion.type;
                paramsNum.question.price = Number(askQuestion.price);
                paramsNum.question.orderId = askQuestion.order_id;
                paramsNum.question.isOnlooker = askQuestion.is_onlooker;
                paramsNum.question.beUserId = askQuestion.be_user_id;
                // sun.question.expiredAt = askQuestion.price;
              }
              // params._jv.relationships.attachments = this.addImg();
              // params._jv.relationships.question = this.addQuestion();
              resolve();
              break;
            }
            case 6:
              paramsNum.postGoodsId = Number(this.dataGoodInfo._jv.id);
              // params.post_goods_id = this.dataGoodInfo._jv.id;
              resolve();
              break;
            default:
              reject();

              this.$refs.toast.show({
                message: this.i18n.t('core.postTypesDoNotMatch')
              }); // ~帖子类型不匹配，请重新进入本页面
          }
        });

        postPromise.then(() => {
          apiRequest.createThread({
            data: paramsNum
          }).then(res => {
            this.save = false;
            if (!this.currentId) {
              this.currentId = res.Data.id;
            }
            // 这是手动发到草稿箱时接口返回的
            this.$refs.toast.show({
              message: this.i18n.t('保存成功')
            });
          });
          // this.$store
          //   .dispatch('jv/post', params)
          //   .then(res => {
          //     this.save = false;
          //     if (!this.currentId) {
          //       this.currentId = res._jv.id;
          //     }
          //     // 这是手动发到草稿箱时接口返回的
          //     this.$refs.toast.show({ message: this.i18n.t('保存成功') });
          //   })
          //   .catch(err => {
          //     console.log(err);
          //   });
        });
      },

      // 自动保存草稿方法
      toDrafts() {
        this.save = true;
        // 自动保存成功
        // const params = {
        //   _jv: {
        //     type: 'threads',
        //     relationships: {
        //       category: {
        //         data: {
        //           type: 'categories',
        //           id: this.two_categoryId || this.categoryId,
        //         },
        //       },
        //     },
        //     links: {
        //       self:
        //         'threads?include=user,category,firstPost,firstPost.images,firstPost.postGoods,question,question.beUser,question.beUser.groups,question.images',
        //     },
        //   },
        //   content: this.textAreaValue,
        //   type: this.type,
        //   price: this.price,
        //   free_words: this.word,
        //   captcha_ticket: this.ticket,
        //   captcha_rand_str: this.randstr,
        //   is_anonymous: this.checked,
        //   is_red_packet: this.is_red_packet,
        //   is_draft: 1,
        //   is_old_draft: 0,
        //   id: this.currentId,
        //   redPacket: {
        //     rule: +this.rule,
        //     money: +this.money,
        //     number: +this.number,
        //     condition: +this.condition,
        //     likenum: +this.likenum,
        //   },
        // };
        const paramsNum = {
          categoriesId: Number(this.thread_id),
          content: this.textAreaValue,
          type: this.type,
          isAnonymous: this.checked ? 1 : 0,
          price: this.price,
          freeWords: this.word,
          id: this.currentId,
          isDraft: 1,
          isOldDraft: 0,
          captchaTicket: this.ticket,
          captchaRandStr: this.randstr,
          redPacket: {
            rule: +this.rule,
            money: +this.money,
            number: +this.number,
            condition: +this.condition,
            likenum: +this.likenum,
            orderId: this.orderSn,
            orderPrice: 0,
          },
        };
        // #ifdef H5|| APP-PLUS
        if (this.vditor && this.type === 1) {
          // params.content = this.vditor
          //   .getValue()
          //   .replace(/blob:/g, '')
          //   .replace(/\n\n/g, '\n\n\n');
          paramsNum.content = this.vditor
            .getValue()
            .replace(/blob:/g, '')
            .replace(/\n\n/g, '\n\n\n');
        }
        // #endif
        // if (this.payType === 1) {
        //   params.attachment_price = this.price;
        //   params.price = '';
        // } else if (this.payType === 0) {
        //   params.attachment_price = '';
        //   params.price = this.price;
        // }
        if (this.payType === 1) {
          paramsNum.attachmentPrice = this.price;
          paramsNum.price = '';
        } else if (this.payType === 0) {
          paramsNum.attachmentPrice = '';
          paramsNum.price = this.price;
        }
        // const { currentPosition } = this;
        // params.longitude = currentPosition.longitude || '';
        // params.latitude = currentPosition.latitude || '';
        // params.location = currentPosition.location || '';
        // params.address = currentPosition.address || '';
        const currentPositions = this.currentPosition;
        if (currentPositions) {
          paramsNum.longitude = Number(currentPositions.longitude) || '';
          paramsNum.latitude = Number(currentPositions.latitude) || '';
          paramsNum.location = currentPositions.location || '';
          paramsNum.address = currentPositions.address || '';
        }
        const postPromise = new Promise((resolve, reject) => {
          switch (this.type) {
            case 0:
              resolve();
              break;
            case 1: {
              // params.title = this.postTitle;
              // params._jv.relationships.attachments = {
              //   data: this.addImg().data.concat(this.addFile().data),
              // };
              paramsNum.title = this.postTitle;
              const num = this.addImg().data.concat(this.addFile().data);
              paramsNum.attachments = [];
              num.forEach(item => {
                paramsNum.attachments.push({
                  id: Number(item.id),
                  type: item.type
                });
              });
              resolve();
              break;
            }
            case 2:
              // params.file_id = this.fileId;
              // params.file_name = this.videoName;
              paramsNum.fileId = this.fileId;
              paramsNum.fileName = this.videoName;
              resolve();
              break;
            case 3: {
              // params._jv.relationships.attachments = this.addImg();
              const numImg = this.addImg().data;
              paramsNum.attachments = [];
              numImg.forEach(item => {
                paramsNum.attachments.push({
                  id: Number(item.id),
                  type: item.type
                });
              });
              resolve();
              break;
            }
            case 4:
              // params.file_id = this.audioBeforeList[0].id;
              // params.file_name = this.audioBeforeList[0].fileName;
              paramsNum.fileId = this.audioBeforeList[0].id;
              paramsNum.fileName = this.audioBeforeList[0].fileName;
              resolve();
              break;
            case 5: {
              const askNum = this.addImg().data;
              const askQuestion = this.addQuestion().data;
              paramsNum.attachments = [];
              paramsNum.question = {};
              askNum.forEach(item => {
                paramsNum.attachments.push({
                  id: Number(item.id),
                  type: item.type
                });
              });
              if (askQuestion) {
                paramsNum.question.type = askQuestion.type;
                paramsNum.question.price = Number(askQuestion.price);
                paramsNum.question.orderId = askQuestion.order_id;
                paramsNum.question.isOnlooker = askQuestion.is_onlooker;
                paramsNum.question.beUserId = askQuestion.be_user_id;
                // sun.question.expiredAt = askQuestion.price;
              }
              // params._jv.relationships.attachments = this.addImg();
              // params._jv.relationships.question = this.addQuestion();
              resolve();
              break;
            }
            case 6:
              // params.post_goods_id = this.dataGoodInfo._jv.id;
              paramsNum.postGoodsId = Number(this.dataGoodInfo._jv.id);
              resolve();
              break;
            default:
              reject();
              this.$refs.toast.show({
                message: this.i18n.t('core.postTypesDoNotMatch')
              }); // ~帖子类型不匹配，请重新进入本页面
          }
        });
        postPromise.then(() => {
          apiRequest.createThread({
            data: paramsNum
          }).then(res => {
            this.save = false;
            if (!this.currentId) {
              this.currentId = res.Data.id;
            }
          });
          // this.$store
          //   .dispatch('jv/post', [params, { custom: { loading: false } }])
          //   .then(res => {
          //     this.save = false;
          //     if (!this.currentId) {
          //       // 自动保存发现了这个帖子没有id，赋予了他id
          //       this.currentId = res._jv.id;
          //     }
          //     // 这是自动发到草稿箱时接口返回的
          //   })
          //   .catch(err => {
          //     console.log(err);
          //   });
        });
      },
      onStartSave() {
        // 监听自动保存;
        this.timer1 = setInterval(() => {
          if (!this.categoryId || this.textAreaValue.length === 0) return;
          // 启动
          this.startSave();
          clearInterval(this.timer1);
          this.timer1 = null;
        }, 10000);
      },

      startSave() {
        // 开始自动保存
        // 自动保存 启动中
        this.timer2 = setInterval(() => {
          if (this.save) {
            // 必须得上一条数据回来才能发下一条呢
          } else {
            this.toDrafts();
          }
        }, 120000);
      },

      addGoods() {
        if (this.operating === 'edit') {
          uni.redirectTo({
            url: `/topic/parse-goods?type=${this.type}&operating=edit&threadId=${this.threadId}`,
          });
        } else {
          // 重新选择商品，需要保存用户编辑的文本
          try {
            uni.setStorageSync('add_goods_text', this.textAreaValue || '');
            // eslint-disable-next-line no-empty
          } catch (e) {}
          // 通过isSaveText字段标记，重新选择商品
          uni.redirectTo({
            url: `/topic/parse-goods?type=${this.type}&isSaveText=1`,
          });
        }
      },
      deleteGoods() {
        this.dataGoodInfo = [];
        this.isShowGoods = false;
      },
      // 允许围观
      changeCheck() {
        // this.checked !== this.checked;
        // #ifdef H5-PLAY || MP-WEIXIN-PLAY || APP-PLUS
        // this.is_onlooker === this.is_onlooker;
        // #endif
      },
      choosePosition() {
        const that = this;
        if (that.currentPosition.location) {
          return;
        }
        this.saveThread();
        // #ifndef MP-WEIXIN
        uni.chooseLocation({
          success: function(res) {
            const positionData = res;
            positionData.location = res.name;
            that.currentPosition = positionData;
          }
        });
        // #endif
        // #ifdef MP-WEIXIN
        uni.getSetting({
          success(res) {
            if (!res.authSetting['scope.userLocation']) {
              uni.authorize({
                scope: 'scope.userLocation',
                success() {
                  uni.chooseLocation({
                    success(res1) {
                      const positionData = res1;
                      positionData.location = res1.name;
                      that.currentPosition = positionData;
                    },
                  });
                },
              });
            } else {
              uni.chooseLocation({
                success(res1) {
                  const positionData = res1;
                  positionData.location = res1.name;
                  that.currentPosition = positionData;
                },
              });
            }
          },
        });
        // #endif
      },
      clearPosition() {
        this.currentPosition = {};
      },
      // 跳转添加主题
      addthetheme() {
        uni.navigateTo({
          url: '/pagesplay_web/AddTheTheme'
        });
      },
      // 跳转红包页
      skipred_packet() {
        if (this.redbagplay === false) return;
        uni.navigateTo({
          url: '/pagesplay_web/compile-money'
        });
      },
      // 清除红包
      clearPacket() {
        this.is_red_packet = ''; // 文字帖类型 0-普通帖 1-红包贴
        this.showmoney = ''; // 展示单个金额多少钱
        this.rule = ''; // 红包贴模式 0-定额 1-随机
        this.money = ''; // 红包金额
        this.number = ''; //  红包数量
        this.condition = ''; // 红包获得条件 0-回复 1-集赞
        this.likenum = ''; // 集赞数
        this.sumtype = '';
      },
      // 暂存帖子信息，以防选完地址回来页面刷新后丢失
      saveThread() {
        uni.removeStorageSync('current_thread'); // 异步移除这个key
        //  if (this.type === 1) {
        //   this.textAreaValue = this.vditor.getValue();
        // }
        const thread = {};
        const items = [
          'postTitle',
          'price',
          'word',
          'fileId',
          'videoName',
          'textAreaValue',
          'categoryIndex',
          'categoryId',
          'checkClassData',
          'uploadFile',
          'videoBeforeList',
          'audioBeforeList',
          'checked',
          'watchChecked',
          'askingPrice',
          'watchShow',
          'priceAsk',
          'beAskId',
          'userImage',
          'beUserName',
          'type',
          'showHidden',
          'payType',
          'showPayType',
          'ioshide',
          'dataGoodInfo',
        ];
        items.forEach(key => {
          if (this[key]) {
            thread[key] = this[key];
          }
        });
        if (this.$refs.uploadFiles) {
          const fileList = this.$refs.uploadFiles.getValue();
          const attachmentList = [];
          fileList.forEach(v => {
            attachmentList.push({
              fileName: v.attributes.fileName,
              url: v.attributes.url,
              _jv: {
                id: v.id,
              },
            });
          });
          thread.attachmentList = attachmentList;
        }
        if (this.$refs.upload) {
          const imgList = this.$refs.upload.getValue();
          imgList.forEach((value, index) => {
            if (value.attributes) {
              imgList[index] = {
                path: value.attributes.thumbUrl,
                id: value.id,
                order: value.attributes.order,
                name: value.attributes.fileName,
                url: value.attributes.url,
              };
            }
          });
          thread.imgList = imgList;
        }
        uni.setStorageSync('current_thread', JSON.stringify(thread));
      },
      setThread() {
        let thread = uni.getStorageSync('current_thread');
        if (!thread) {
          return;
        }

        thread = JSON.parse(thread);
        this.dataGoodInfo = thread.dataGoodInfo;
        Object.getOwnPropertyNames(thread).forEach(key => {
          if (key === 'imgList') {
            const threadImgList = thread[key];
            threadImgList.forEach((v, index) => {
              threadImgList[index] = {
                thumbUrl: v.path,
                _jv: {
                  id: v.id,
                },
                order: v.order,
                fileName: v.name,
                url: v.url,
              };
            });
            const image = {
              firstPost: {
                images: []
              }
            };
            image.firstPost.images = thread[key];
            this.setAnnex('img', image);
          } else {
            this[key] = thread[key];
          }
        });
        if (this.videoBeforeList.length > 0) {
          // this.videoPercent = 1;
          this.percent = 1;
        }

        uni.removeStorageSync('current_thread');
      },
      focusEvent() {
        // 这是获取焦点
      },
      toolBarClick(type) {
        let text = '';
        if (type === 'bold') {
          text = `${`${this.textAreaValue.slice(
          0,
          this.cursor,
        )}**粗体文字**${this.textAreaValue.slice(this.cursor)}`}`;
          this.cursor += 2;
          this.focusEvent(this.cursor);
        } else if (type === 'italic') {
          // this.textareaValue += '*斜体* ';
          text = `${`${this.textAreaValue.slice(0, this.cursor)}__${this.textAreaValue.slice(
          this.cursor,
        )}`}`;
          this.cursor += 1;
          this.focusEvent(this.cursor);
        } else if (type === 'title') {
          text = `${`${this.textAreaValue.slice(0, this.cursor)}\n### ${this.textAreaValue.slice(
          this.cursor,
        )}`}`;
          this.cursor += 4;
          this.focusEvent(this.cursor);
        } else if (type === 'quote') {
          text = `${`${this.textAreaValue.slice(0, this.cursor)}\n> ${this.textAreaValue.slice(
          this.cursor,
        )}`}`;
          this.cursor += 1;
          this.focusEvent(this.cursor);
        } else if (type === 'link') {
          text = `${`${this.textAreaValue.slice(0, this.cursor)}[](url)${this.textAreaValue.slice(
          this.cursor,
        )}`}`;
          this.cursor += 1;
          this.focusEvent(this.cursor);
        } else if (type === 'code') {
          text = `${`${this.textAreaValue.slice(0, this.cursor)}\`\`${this.textAreaValue.slice(
          this.cursor,
        )}`}`;
          this.cursor += 1;
          this.focusEvent(this.cursor);
        } else if (type === 'strikethrough') {
          text = `${`${this.textAreaValue.slice(0, this.cursor)}~~~~${this.textAreaValue.slice(
          this.cursor,
        )}`}`;
          this.cursor += 2;
          this.focusEvent(this.cursor);
        }
        this.textAreaValue = text;
      },
      ...mapMutations({
        setAtMember: 'atMember/SET_ATMEMBER',
      }),
      // 文章类型（0:文字  1:帖子  2:视频  3:图片）
      // 处理金额
      /* eslint-disable */
      checkNum(e) {
        let that = this;
        let price = e.target.value;
        let maxLength = price.indexOf('.');
        if (price.indexOf('.') < 0 && price != '') {
          // '超过4位则大于1万元';
          if (price.length > 6) {
            price = price.substring(0, price.length - 1);
            uni.showToast({
              title: that.c.TheAmountCannotExceedOneMillion,
              icon: 'none',
            });
          } else {
            price = parseFloat(price);
          }
        } else if (price.indexOf('.') == 0) {
          //'首位小数点情况'
          price = price.replace(/[^$#$]/g, '0.');
          price = price.replace(/\.{2,}/g, '.');
        } else if (!/^(\d?)+(\.\d{0,2})?$/.test(price)) {
          //去掉最后一位
          price = price.substring(0, price.length - 1);
        }
        that.$nextTick(function() {
          //'有小数点时，最大长度为9位，没有则是7位'
          that.maxLength = maxLength == -1 ? 7 : 10;
          that.inputPrice = price;
        });
      },
      // video相关方法
      videoDel() {
        this.deleteType = 2;
        // this.deleteId = id;
        // this.deleteIndex = del;
        this.$refs.deletePopup.open();
        this.deleteTip = this.i18n.t('core.deleteVideoSure');
      },
      playVideo(video) {
        // #ifdef MP-WEiXIN
        this.controlsStatus = true;
        this.videoContext.play();
        this.videoContext.requestFullScreen();
        // #endif
        // #ifdef H5|| APP-PLUS
        uni.$emit('playVideo', video);
        // #endif
      },
      fullscreenchange(e) {
        this.fullscreenStatus = e.detail.fullScreen;
        if (!e.detail.fullScreen) {
          this.controlsStatus = false;
          this.videoContext.pause();
        }
      },
      // 点击表情
      emojiclick() {
        this.emojiShow = !this.emojiShow;
        this.textShow = !this.textShow;
      },
      // 弹框相关方法
      contBlur(e) {
        this.cursor = e.detail.cursor;
      },
      diaLogClose() {
        this.$refs.popup.close();
        this.popupStatus = false;
        this.textShow = true;
      },
      diaLogOk() {
        // if (Number(this.inputPrice) < Number(this.lowestPrice)) {
        //   uni.showToast({
        //     title: `打赏金额不能低于${this.lowestPrice}元`,
        //     icon: 'none',
        //   });
        //   return;
        // }
        if (this.forums.set_site.site_minimum_amount === '') {
          if (this.inputPrice < '0.1') {
            uni.showToast({
              title: this.i18n.t('core.TheAmountCannotBeLessThanOneYuan'),
              icon: 'none',
            });
            return;
          }
        } else {
          if (this.inputPrice < this.forums.set_site.site_minimum_amount) {
            uni.showToast({
              title: this.i18n.t('core.TheAmountCannotBeLessThanMinMoney') +
                this.forums.set_site.site_minimum_amount +
                this.i18n.t('discuzq.post.yuan'),
              icon: 'none',
            });
            return;
          }
        }
        if (this.type === 5) {
          this.priceAsk = this.inputPrice;
          this.$refs.popup.close();
          this.popupStatus = false;
          this.textShow = true;
          this.postClick();
          return;
        }

        if (this.setType === 'pay') {
          this.price = this.inputPrice;
        } else {
          this.word = this.inputWord;
        }
        this.$refs.popup.close();
        this.popupStatus = false;
        this.textShow = true;
      },
      percentageClick(index) {
        this.word = this.freepercentage[index].pay;
        this.percentagedisplay = this.freepercentage[index].name;
        this.setType = 'word';
        this.freewords = [];
        this.freewords.push(this.freepercentage[index]);
        this.$refs.popupBtm.close();
      },
      moneyClick(index) {
        // if (this.forums.set_site.site_onlooker_price === 0) {
        //   this.watchShow = false;
        // } else if (index === 0) {
        //   this.payType = 0;
        //   // this.postClick();
        //   if (this.payType === 0) {
        //     this.showPayType = this.i18n.t('discuzq.post.TheContentAndTheAccessoriesIsFree');
        //   }
        //   this.watchShow = false;
        // } else {
        //   this.watchShow = true;
        // }
        if (this.forums.set_site.site_onlooker_price === 0) {
          this.watchShow = false;
        }
        if (index === 0) {
          if (this.type === 5) {
            this.watchShow = false;
            this.postClick();
            return;
          }
          if (this.type !== 1 && this.type !== 5) {
            this.payType = 0;
            if (this.payType === 0) {
              this.showPayType = this.i18n.t('discuzq.post.TheContentAndTheAccessoriesIsFree');
            }
          }
        } else {
          this.watchShow = true;
        }
        this.setType = 'pay';
        this.payNumCheck = [];
        this.payNumCheck.push(this.payNum[index]);
        // 自定义金额
        if (this.payNumCheck[0].name === this.i18n.t('discuzq.post.customize')) {
          this.textShow = false;
          this.$refs.popupBtm.close();
          this.popupStatus = true;
          this.$nextTick(() => {
            this.inputPrice = '';
            this.$refs.popup.open();
            this.textShow = false;
          });
        } else {
          if (this.type === 5 && index !== 0) {
            this.priceAsk = this.payNumCheck[0].pay;
            this.$refs.popupBtm.close();
            this.postClick();
            this.textShow = true;
            return;
          }
          this.price = this.payNumCheck[0].pay;
          this.$refs.popupBtm.close();
          this.textShow = true;
        }
      },
      // 点击显示查看支付的抽屉
      lookPay() {
        this.$refs.lookPayPopup.open();
      },
      // 取消查看支付选择
      cancelLookPay() {
        this.$refs.lookPayPopup.close();
      },
      // 选择支付查看的方式 0均免费， 1内容免费，附件付费，  2内容和附件都付费
      choicePayType(type) {
        if (type === 0) {
          // this.redlongshow = true; // 红包长文付费时候是否显示
          this.payNumCheck = [];
          this.price = '';
          this.showPayType = this.i18n.t('discuzq.post.TheContentAndTheAccessoriesIsFree');
        } else if (type === 1) {
          // this.redlongshow = false; // 红包长文付费时候是否显示
          this.payNumCheck = [];
          this.showPayType = this.i18n.t('discuzq.post.TheContentIsFreeAndTheAccessoriesArePaid');
          this.payNum[0].name = '￥1';
          this.payNum[0].pay = 1;
        } else {
          // this.redlongshow = false; // 红包长文付费时候是否显示
          this.payNumCheck = [];
          this.payNum[0].name = '￥1';
          this.showPayType = this.i18n.t('discuzq.post.TheContentAndTheAccessoriesIsPaid');
          this.payNum[0].pay = 1;
        }
        this.payType = type;
        this.$refs.lookPayPopup.close();
      },
      cellClick(type) {
        this.setType = type;
        this.$refs.popupBtm.open();
        this.textShow = false;
      },
      // 提问价格
      postAnswerClick(type) {

        // this.popupStatus = true;
        // this.$nextTick(() => {
        //   this.inputPrice = '';
        //   this.$refs.popup.open();
        //   this.textShow = false;
        // });
        this.$refs.popupBtm.open();
        this.textShow = false; //文本域是否显示
      },
      cancel() {
        this.$refs.popupBtm.close();
        this.textShow = true;
      },
      // 图片上传相关方法
      uploadClick(e) {
        this.uploadStatus = e;
      },
      uploadChange(e, status) {
        this.uploadFile = e;
        this.uploadStatus = status;
      },
      uploadClear(list, del) {
        const id = list.id;
        this.deleteType = 0;
        this.deleteId = id;
        this.deleteIndex = del;
        this.$refs.deletePopup.open();
        this.deleteTip = this.i18n.t('core.deleteImgSure');
      },
      // 音频上传改变
      uploadAudioChange(e) {
        this.audioBeforeList = e;
      },
      audioDel() {
        this.deleteType = 3;
        this.$refs.deletePopup.open();
        this.deleteTip = this.i18n.t('core.deleteAudioSure');
      },
      // 表情点击事件
      getEmojiClick(code) {
        let text = '';
        text = `${this.textAreaValue.slice(0, this.cursor) +
        code +
        this.textAreaValue.slice(this.cursor)}`;
        this.cursor = text.length;
        this.textAreaValue = text;
        this.emojiShow = false;
        this.textShow = true;
      },
      // @人员跳转
      callClick() {
        uni.navigateTo({
          url: '/pages/user/at-member'
        });
      },
      topicPage() {
        uni.navigateTo({
          url: '/topic/topic'
        });
      },
      // 分类点击
      checkClass(e, index, f_id) {
        // 当前一级分类
        // 单选功能
        this.two_categoryId = '';
        this.checkClassData = [];
        if (this.categoryId != f_id) {
          this.categoryId = f_id;
          this.checkClassData.push(e);
          this.secondallcategories = e.children || []; //二级分类点击事件
        } else {
          this.categoryId = '';
        }
      },
      checkClassing(e, index, id) {
        // 二级下拉单选功能
        // 当前二级分类
        if (+this.two_categoryId != +id) {
          this.two_categoryId = id;
        } else {
          this.two_categoryId = '';
        }
      },
      // 主题提问价格
      payClickShow() {
        if (!this.$store.getters['session/get']('isLogin')) {
          // #ifdef MP-WEIXIN
          this.mpLoginMode();
          // #endif
          // #ifdef H5|| APP-PLUS
          this.$store.dispatch('session/setUrl', this.curUrl);
          this.h5LoginMode();
          // #endif
        }
        this.payStatus = false;
        if (!this.forums.paycenter.wxpay_close) {
          this.payShowStatus = false;
          return;
        } else if (this.forums.paycenter.wxpay_close && this.forums.other.can_create_thread_paid) {
          // #ifndef H5|| APP-PLUS
          if (this.system === 'ios') {
            this.postShow = true;
            this.payShowStatus = false;
            this.ioshide = false;
            return;
          } else {
            this.ioshide = true;
            this.payShowStatus = true;
          }
          // #endif
          // #ifdef H5|| APP-PLUS
          this.ioshide = true;
          this.payShowStatus = true;
          // #endif
        } else {
          this.ioshide = false;
          this.payShowStatus = false;
          return;
        }
        this.payTypeText = this.t.pay + this.t.payAskingPrice;
        this.priceAsk = parseFloat(this.thread.price);
        this.$nextTick(() => {
          this.$refs.payShow.payClickShow(this.payTypeVal);
        });
      },
      // 支付方式选择完成点击确定时
      paysureShow(payType) {
        uni.setStorage({
          key: 'page',
          data: `/topic/post?type=5&categoryId=${this.categoryid}&categoryIndex=${this.categoryindex}`,
        });
        //设置本地一个page字段
        if (payType === 0) {
          //如果是微信支付
          // #ifdef H5|| APP-PLUS
          if (this.isWeixin === true && this.user.wechat === undefined) {
            this.$refs.wechatPopup.open();
            return;
          }
          if (this.isWeixin === true && this.user.wechat && this.user.wechat.mp_openid === '') {
            this.$refs.wechatPopup.open();
            return;
          }
          // #endif

          // #ifdef MP-WEIXIN
          if (
            this.user.wechat === undefined ||
            (this.user.wechat && this.user.wechat.min_openid === '')
          ) {
            this.$refs.wechatPopup.open();
            return;
          }
          // #endif
          if (this.is_red_packet === 1 || this.is_red_packet === '1') {
            //当前是红包帖的时候
            if (this.type === 0) {
              // 当前是识别红包帖
              this.creatOrder(this.money, 20, '', payType);
            }
            if (this.type === 1) {
              // 当前是识别长文红包帖
              this.creatOrder(this.money, 21, '', payType);
            }
          } else {
            //如果当前是问答的逻辑就走这
            this.creatOrder(this.priceAsk, 5, '', payType);
          }
        } else if (payType === 1) {
          console.log('钱包')
          // 这是详情页获取到的支付方式---钱包
        }
      },
      // 输入密码完成时
      onInput(val) {
        this.value = val;
        if (this.is_red_packet === 1 || this.is_red_packet === '1') {
          if (this.type === 0) {
            // 可以识别红包帖
            this.creatOrder(this.money, 20, val, 1);
          }
          if (this.type === 1) {
            // 可以识别长文红包帖
            this.creatOrder(this.money, 21, val, 1);
          }
        } else {
          this.creatOrder(this.priceAsk, 5, val, 1);
        }
      },
      creatOrder(amount, type, value, payType) {
        const params = {
          _jv: {
            type: 'orders',
          },
          type,
          payee_id: this.beAskId,
          amount,
          is_anonymous: this.checked ? '0' : '1',
        };
        this.$store
          .dispatch('jv/post', params)
          .then(res => {
            this.orderSn = res.order_sn;
            if (payType === 0) {
              // 微信支付
              if (this.browser == 0) {
                // 这是微信小程序内的支付
                this.orderPay(13, value, this.orderSn, payType, '0');
              } else {
                // 这是除微信小程序之外, this.isWeixin, this.isPhone
                if (this.isWeixin && this.isPhone) {
                  // 这是微信浏览器
                  this.orderPay(12, value, this.orderSn, payType, '1');
                } else if (this.isPhone) {
                  this.orderPay(20, value, this.orderSn, 1, '2');
                } else {
                  // 这是pc，没调接口之前
                  this.orderPay(10, value, this.orderSn, payType, '3');
                }
              }
            } else if (payType === 1) {
              // 钱包支付
              this.orderPay(20, value, this.orderSn, payType);
            }
          })
          .catch(err => {
            console.log(err);
          });
      },
      // 订单支付       broswerType: 0是小程序，微信1是浏览器，2是h5，3是pc
      orderPay(type, value, orderSn, payType, broswerType) {
        let params = {};
        if (payType === 0) {
          params = {
            _jv: {
              type: `trade/pay/order/${orderSn}`,
            },
            payment_type: type,
          };
        } else if (payType === 1) {
          params = {
            _jv: {
              type: `trade/pay/order/${orderSn}`,
            },
            payment_type: type,
            pay_password: value,
          };
        }
        this.$store
          .dispatch('jv/post', params)
          .then(res => {
            this.wxRes = res;
            if (payType === 0) {
              if (broswerType === '0') {
                this.wechatPay(
                  res.wechat_js.timeStamp,
                  res.wechat_js.nonceStr,
                  res.wechat_js.package,
                  res.wechat_js.signType,
                  res.wechat_js.paySign,
                );
              } else if (broswerType === '1') {
                if (typeof WeixinJSBridge === 'undefined') {
                  if (document.addEventListener) {
                    document.addEventListener('WeixinJSBridgeReady', this.onBridgeReady(res), false);
                  } else if (document.attachEvent) {
                    document.attachEvent('WeixinJSBridgeReady', this.onBridgeReady(res));
                    document.attachEvent('onWeixinJSBridgeReady', this.onBridgeReady(res));
                  }
                } else {
                  this.onBridgeReady(res);
                }
              } else if (broswerType === '2') {
                this.postThread().then(data => {
                  // window.location.href = `${res.wechat_h5_link}&redirect_url=${encodeURIComponent(window.location.origin /topic/indexdex?id='+ data._jv.id)}`;
                  this.postLoading = false;
                  uni.hideLoading();
                  if (data && data.isApproved === 1) {
                    // 因为设置了虚拟滚动，所以将会去除所有对列表数据的操作，只会刷新才会更新现有数据
                    this.$u.event.$emit('refreshHome', res);
                  }
                  if (data && data.Data && data.Data.id) {
                    uni.redirectTo({
                      url: `/topic/index?id=${data.Data.id}`,
                    });
                  }
                });
              } else if (broswerType === '3') {
                if (res) {
                  this.codeUrl = res.wechat_qrcode;
                  this.payShowStatus = false;
                  this.$refs.codePopup.open();
                  this.qrcodeShow = true;
                  payWechat = setInterval(() => {
                    if (this.payStatus === 1) {
                      clearInterval(payWechat);
                      return;
                    }
                    this.getOrderStatus(this.orderSn, broswerType);
                    uni.hideLoading();
                  }, 3000);
                }
              }
            } else if (payType === 1) {
              if (res.wallet_pay.result === 'success') {
                this.$store.dispatch('jv/get', [`users/${this.currentLoginId}`, {}]);
                this.coverLoading = false;
                this.postThread().then(res => {
                  this.postLoading = false;
                  uni.hideLoading();
                  if (res && res.isApproved === 1) {
                    // 因为设置了虚拟滚动，所以将会去除所有对列表数据的操作，只会刷新才会更新现有数据
                    this.$u.event.$emit('refreshHome', res);
                  }
                  if (res && res.Data && res.Data.id) {
                    uni.redirectTo({
                      url: `/topic/index?id=${res.Data.id}`,
                    });
                  }
                });
              }
              this.coverLoading = false;
            }
          })
          .catch(err => {
            // 清空支付的密码
            console.log(err);
            this.$refs.payShow.clearPassword();
          });
      },
      getOrderStatus(orderSn, broswerType) {
        this.$store
          .dispatch('jv/get', [`orders/${orderSn}`, {
            custom: {
              loading: false
            }
          }])
          .then(res => {
            this.payStatus = res.status;
            if (this.payStatus === 1) {
              if (broswerType === '2') {
                // return false;
              } else if (broswerType === '3') {
                // 这是pc扫码支付完成
                this.$refs.codePopup.close();
                this.qrcodeShow = false;
                this.postThread();
              } else if (broswerType === '0') {
                this.postThread().then(res => {
                  this.postLoading = false;
                  uni.hideLoading();
                  if (res && res.isApproved === 1) {
                    // 因为设置了虚拟滚动，所以将会去除所有对列表数据的操作，只会刷新才会更新现有数据
                    this.$u.event.$emit('refreshHome', res);
                  }
                  if (res && res.Data && res.Data.id) {
                    uni.redirectTo({
                      url: `/topic/index?id=${res.Data.id}`,
                    });
                  }
                });
              } else if (broswerType === '1') {
                this.postThread().then(res => {
                  this.postLoading = false;
                  uni.hideLoading();
                  if (res && res.isApproved === 1) {
                    // 因为设置了虚拟滚动，所以将会去除所有对列表数据的操作，只会刷新才会更新现有数据
                    this.$u.event.$emit('refreshHome', res);
                  }
                  if (res && res.Data && res.Data.id) {
                    uni.redirectTo({
                      url: `/topic/index?id=${res.Data.id}`,
                    });
                  }
                });
              }
              this.$refs.toast.show({
                message: this.i18n.t('pay.paySuccess')
              });
            }
          })
          .catch(err => {
            console.log(err);
            this.coverLoading = false;
            this.$refs.toast.show({
              message: this.i18n.t('pay.payFail')
            });
          });
      },
      wechatPay(timeStamp, nonceStr, packageVal, signType, paySign) {
        // 小程序支付。
        const _this = this;
        uni.requestPayment({
          provider: 'wxpay',
          timeStamp,
          nonceStr,
          package: packageVal,
          signType,
          paySign,
          success(res) {
            _this.coverLoading = true;
            payWechat = setInterval(() => {
              if (_this.payStatus === 1) {
                clearInterval(payWechat);
                return;
              }
              _this.getOrderStatus(_this.orderSn, '0');
            }, 3000);
          },
          fail(err) {
            _this.payShowStatus = false;
            _this.coverLoading = false;
            _this.$refs.toast.show({
              message: _this.p.payFail
            });
          },
        });
      },
      // 非小程序内微信支付
      onBridgeReady(data) {
        // const that = this;
        WeixinJSBridge.invoke(
          'getBrandWCPayRequest', {
            appId: data.wechat_js.appId, // 公众号名称，由商户传入
            timeStamp: data.wechat_js.timeStamp, // 时间戳，自1970年以来的秒数
            nonceStr: data.wechat_js.nonceStr, // 随机串
            package: data.wechat_js.package,
            signType: 'MD5', // 微信签名方式：
            paySign: data.wechat_js.paySign, // 微信签名
          },
          function(data) {
            // alert('支付唤醒');
            if (data.err_msg == 'get_brand_wcpay_request:ok') {
              //微信支付成功，进行支付成功处理
            } else if (data.err_msg == 'get_brand_wcpay_request:cancel') {
              // 取消支付
              clearInterval(payWechat);
              resolve;
            } else if (data.err_msg == 'get_brand_wcpay_request:fail') {
              // 支付失败
              clearInterval(payWechat);
              resolve;
            }
          },
        );
        payWechat = setInterval(() => {
          if (this.payStatus === 1) {
            clearInterval(payWechat);
            return;
          }
          this.getOrderStatus(this.orderSn, '1');
        }, 3000);
      },
      // 选择支付方式，获取值
      radioChange(val) {},

      // #ifndef H5 || APP-PLUS
      // // 发布按钮点击，检测条件是否符合，符合的话调用接口
      // postClick() {
      //   this.payTypeText = this.i18n.t('topic.pay') + this.i18n.t('discuzq.post.payAskingPrice'); //~支付+~提问价格
      //   if (this.type === 1) {
      //     if (this.vditor) {
      //       this.textAreaValue = this.vditor
      //         .getValue()
      //         .replace(/blob\:/g, '')
      //         .replace(/\n\n/g, '\n\n\n');
      //     }
      //   }

      //   let status = true;
      //   switch (this.type) {
      //     case 0:
      //       if (this.textAreaValue.length < 1) {
      //         this.$refs.toast.show({ message: this.i18n.t('discuzq.post.theContentCanNotBeBlank') }); //~内容不能为空
      //         status = false;
      //       } else {
      //         status = true;
      //       }
      //       break;
      //     case 1:
      //       if (this.postTitle.length < 1) {
      //         this.$refs.toast.show({ message: this.i18n.t('discuzq.post.theTitleCanNotBeBlank') }); //~标题不能为空
      //         status = false;
      //       } else if (this.textAreaValue.length < 1) {
      //         this.$refs.toast.show({ message: this.i18n.t('discuzq.post.theContentCanNotBeBlank') }); //~内容不能为空
      //         status = false;
      //       } else if (!this.uploadStatus) {
      //         this.$refs.toast.show({
      //           message: this.i18n.t('discuzq.post.pleaseWaitForTheImageUploadToComplete'), //~请等待图片上传完成
      //         });
      //         status = false;
      //       } else if (this.payType === 1) {
      //         // 内容免费，附件付费
      //         if (this.$refs.uploadFiles.getValue().length === 0) {
      //           // 附件不能为空
      //           this.$refs.toast.show({
      //             message: this.i18n.t('discuzq.post.attachmentCannotBeEmpty'),
      //           });
      //           status = false;
      //         } else if (this.price === 0) {
      //           // 选择付费后，价格不能为空
      //           this.$refs.toast.show({
      //             message: this.i18n.t('discuzq.post.priceCannotBeFree'),
      //           });
      //           status = false;
      //         } else {
      //           status = true;
      //         }
      //       } else if (this.payType === 2) {
      //         // 内容附件均付费
      //         if (this.price === 0) {
      //           this.$refs.toast.show({
      //             message: this.i18n.t('discuzq.post.priceCannotBeFree'), //~选择类型为付费类型后，价格不能为0
      //           });
      //           status = false;
      //         } else {
      //           status = true;
      //         }
      //       } else {
      //         status = true;
      //       }
      //       break;
      //     case 2:
      //       if (this.videoBeforeList.length < 1) {
      //         this.$refs.toast.show({ message: this.i18n.t('discuzq.post.videoCannotBeEmpty') }); //~视频不能为空
      //         status = false;
      //       } else if (this.percent !== 1) {
      //         this.$refs.toast.show({
      //           message: this.i18n.t('discuzq.post.pleaseWaitForTheVideoUploadToComplete'), //~请等待视频上传完成
      //         });
      //         status = false;
      //       } else if (this.payType === 2) {
      //         // 内容附件均付费
      //         if (this.price === 0) {
      //           this.$refs.toast.show({
      //             message: this.i18n.t('discuzq.post.priceCannotBeFree'), //~选择类型为付费类型后，价格不能为0
      //           });
      //           status = false;
      //         } else {
      //           status = true;
      //         }
      //       } else {
      //         status = true;
      //       }
      //       break;
      //     case 3:
      //       if (this.operating !== 'edit' || this.operating === 'draft') {
      //         if (!this.uploadStatus) {
      //           this.$refs.toast.show({
      //             message: this.i18n.t('discuzq.post.pleaseWaitForTheImageUploadToComplete'),
      //           });
      //           status = false;
      //         } else if (this.uploadFile.length < 1) {
      //           this.$refs.toast.show({
      //             message: this.i18n.t('discuzq.post.imageCannotBeEmpty'),
      //           });
      //           status = false;
      //         } else if (this.payType === 2) {
      //           // 内容附件均付费
      //           if (this.price === 0) {
      //             this.$refs.toast.show({
      //               message: this.i18n.t('discuzq.post.priceCannotBeFree'),
      //             });
      //             status = false;
      //           } else {
      //             status = true;
      //           }
      //         } else {
      //           status = true;
      //         }
      //       } else {
      //         if (!this.uploadStatus) {
      //           this.$refs.toast.show({
      //             message: this.i18n.t('discuzq.post.pleaseWaitForTheImageUploadToComplete'), //~请等待图片上传完成
      //           });
      //           status = false;
      //         } else if (this.payType === 2) {
      //           // 内容附件均付费
      //           if (this.price === 0) {
      //             this.$refs.toast.show({
      //               message: this.i18n.t('discuzq.post.priceCannotBeFree'), //~选择类型为付费类型后，价格不能为0
      //             });
      //             status = false;
      //           } else {
      //             status = true;
      //           }
      //         } else {
      //           status = true;
      //         }
      //       }
      //       break;
      //     case 4:
      //       if (this.audioBeforeList.length < 1) {
      //         this.$refs.toast.show({
      //           message: this.i18n.t('discuzq.post.audioCannotBeEmpty'), //~语音不能为空
      //         });
      //         status = false;
      //       } else {
      //         status = true;
      //       }
      //       break;
      //     case 5:
      //       if (this.beAskId === '') {
      //         this.$refs.toast.show({
      //           message: this.i18n.t('discuzq.post.pleaseSelectTheUserToBeAsked'), //~请选择被提问用户
      //         });
      //         status = false;
      //       } else if (this.textAreaValue.length < 1) {
      //         this.$refs.toast.show({ message: this.i18n.t('discuzq.post.theContentCanNotBeBlank') }); //~内容不能为空
      //         status = false;
      //       }
      //       // else if (Number(this.priceAsk) < Number(this.forums.other.can_be_asked_money)) {
      //       //     this.$refs.toast.show({ message: `打赏金额不能低于${this.forums.other.can_be_asked_money}元` });
      //       // }
      //       else if (this.watchShow) {
      //         //如果显示他人围观
      //         this.payShowStatus = true;
      //         this.$nextTick(() => {
      //           this.$refs.payShow.payClickShow();
      //         });
      //       }
      //       break;
      //     case 6:
      //       if (this.dataGoodInfo === '' || this.dataGoodInfo.length === 0) {
      //         this.$refs.toast.show({ message: this.i18n.t('core.productInformationDoesNotExist') }); //~商品信息不存在
      //         status = false;
      //       } else {
      //         status = true;
      //       }
      //       break;
      //     default:
      //       status = false;
      //       this.$refs.toast.show({ message: this.i18n.t('core.postTypesDoNotMatch') }); //~帖子类型不匹配，请重新进入本页面
      //   }
      //   if (status) {
      //     this.save = true;
      //     clearInterval(this.timer1);
      //     this.timer1 = null;
      //     clearInterval(this.timer2);
      //     this.timer2 = null;
      //     // 定时器消除成功
      //     if (this.type !== 5) {
      //       this.postLoading = true;
      //       // uni.showLoading();
      //     }
      //     if (this.operating === 'edit') {
      //       // if (this.type === 5) {
      //       //   // this.beUserName =
      //       // }
      //       // 因为设置了虚拟滚动，所以将会去除所有对列表数据的操作，只会刷新才会更新现有数据
      //       // this.$u.event.$emit('updateLocation', this.postDetails._jv.id, this.currentPosition);
      //       if (this.type === 3) {
      //         if (this.uploadFile.length < 1) {
      //           this.$refs.toast.show({
      //             message: this.i18n.t('discuzq.post.imageCannotBeEmpty'), //~图片不能为空
      //           });
      //           uni.hideLoading();
      //           this.postLoading = false;
      //         } else {
      //           this.editThread().then(res => {
      //             this.postLoading = false;
      //             uni.hideLoading();
      //             // uni.navigateBack({
      //             //   delta: 1,
      //             // });
      //             if (res && this.threadId) {
      //               uni.redirectTo({
      //                 url: `/topic/index?id=${this.threadId}`,
      //               });
      //             }
      //           });
      //         }
      //       } else {
      //         this.editThread().then(res => {
      //           this.postLoading = false;
      //           uni.hideLoading();
      //           // uni.navigateBack({
      //           //   delta: 1,
      //           // });
      //           if (res && this.threadId) {
      //             uni.redirectTo({
      //               url: `/topic/index?id=${this.threadId}`,
      //             });
      //           }
      //         });
      //       }
      //     } else {
      //       if (this.forums.qcloud.qcloud_captcha && this.forums.other.create_thread_with_captcha) {
      //         if (!this.ticket || !this.randstr) {
      //           this.toTCaptcha();
      //           return false;
      //         }
      //       }
      //       if (!this.watchShow || this.type !== 5) {
      //         if (this.is_red_packet === 1 || this.is_red_packet === '1') {
      //           this.$nextTick(() => {
      //             this.$refs.payShowtwo.payClickShow();
      //           });
      //         } else {
      //           this.postThread().then(res => {
      //             this.postLoading = false;
      //             uni.hideLoading();
      //             if (res && res.isApproved === 1) {
      //               this.$u.event.$emit('refreshHome', res);
      //             }
      //             if (res && res.Data && res.Data.id) {
      //               uni.redirectTo({
      //                 url: `/topic/index?id=${res.Data.id}`,
      //               });
      //             }
      //           });
      //         }
      //       }
      //     }
      //   }
      // },
      // #endif

      // 发布按钮点击，插入加入发布红包逻辑
      postClick() {
        this.payTypeText = this.i18n.t('topic.pay') + this.i18n.t('discuzq.post.payAskingPrice'); //~支付+~提问价格
        if (this.type === 1) {}

        let status = true; //监听器
        switch (this.type) {
          case 0:
            if (this.textAreaValue.length < 1) {
              this.$refs.toast.show({
                message: this.i18n.t('discuzq.post.theContentCanNotBeBlank')
              }); //~内容不能为空
              status = false;
            } else {
              status = true;
            }
            break;
          case 1:
            if (this.postTitle.length < 1) {
              this.$refs.toast.show({
                message: this.i18n.t('discuzq.post.theTitleCanNotBeBlank')
              }); //~标题不能为空
              status = false;
            } else if (this.textAreaValue.length < 1) {
              this.$refs.toast.show({
                message: this.i18n.t('discuzq.post.theContentCanNotBeBlank')
              }); //~内容不能为空
              status = false;
            } else if (!this.uploadStatus) {
              this.$refs.toast.show({
                message: this.i18n.t('discuzq.post.pleaseWaitForTheImageUploadToComplete'), //~请等待图片上传完成
              });
              status = false;
            } else if (this.payType === 1) {
              // 内容免费，附件付费
              if (this.$refs.uploadFiles.getValue().length === 0) {
                // 附件不能为空
                this.$refs.toast.show({
                  message: this.i18n.t('discuzq.post.attachmentCannotBeEmpty'),
                });
                status = false;
              } else if (this.price === 0) {
                // 选择付费后，价格不能为空
                this.$refs.toast.show({
                  message: this.i18n.t('discuzq.post.priceCannotBeFree'),
                });
                status = false;
              } else {
                status = true;
              }
            } else if (this.payType === 2) {
              // 内容附件均付费
              if (this.price === 0) {
                this.$refs.toast.show({
                  message: this.i18n.t('discuzq.post.priceCannotBeFree'), //~选择类型为付费类型后，价格不能为0
                });
                status = false;
              } else {
                status = true;
              }
            } else {
              status = true;
            }
            break;
          case 2:
            if (this.videoBeforeList.length < 1) {
              this.$refs.toast.show({
                message: this.i18n.t('discuzq.post.videoCannotBeEmpty')
              }); //~视频不能为空
              status = false;
            } else if (this.percent !== 1) {
              this.$refs.toast.show({
                message: this.i18n.t('discuzq.post.pleaseWaitForTheVideoUploadToComplete'), //~请等待视频上传完成
              });
              status = false;
            } else if (this.payType === 2) {
              // 内容附件均付费
              if (this.price === 0) {
                this.$refs.toast.show({
                  message: this.i18n.t('discuzq.post.priceCannotBeFree'), //~选择类型为付费类型后，价格不能为0
                });
                status = false;
              } else {
                status = true;
              }
            } else {
              status = true;
            }
            break;
          case 3:
            if (this.operating !== 'edit' || this.operating === 'draft') {
              if (!this.uploadStatus) {
                this.$refs.toast.show({
                  message: this.i18n.t('discuzq.post.pleaseWaitForTheImageUploadToComplete'),
                });
                status = false;
              } else if (this.uploadFile.length < 1) {
                this.$refs.toast.show({
                  message: this.i18n.t('discuzq.post.imageCannotBeEmpty'),
                });
                status = false;
              } else if (this.payType === 2) {
                // 内容附件均付费
                if (this.price === 0) {
                  this.$refs.toast.show({
                    message: this.i18n.t('discuzq.post.priceCannotBeFree'),
                  });
                  status = false;
                } else {
                  status = true;
                }
              } else {
                status = true;
              }
            } else {
              if (!this.uploadStatus) {
                this.$refs.toast.show({
                  message: this.i18n.t('discuzq.post.pleaseWaitForTheImageUploadToComplete'), //~请等待图片上传完成
                });
                status = false;
              } else if (this.payType === 2) {
                // 内容附件均付费
                if (this.price === 0) {
                  this.$refs.toast.show({
                    message: this.i18n.t('discuzq.post.priceCannotBeFree'), //~选择类型为付费类型后，价格不能为0
                  });
                  status = false;
                } else {
                  status = true;
                }
              } else {
                status = true;
              }
            }
            break;
          case 4:
            if (this.audioBeforeList.length < 1) {
              this.$refs.toast.show({
                message: this.i18n.t('discuzq.post.audioCannotBeEmpty'), //~语音不能为空
              });
              status = false;
            } else {
              status = true;
            }
            break;
          case 5:
            if (this.beAskId === '') {
              this.$refs.toast.show({
                message: this.i18n.t('discuzq.post.pleaseSelectTheUserToBeAsked'), //~请选择被提问用户
              });
              status = false;
            } else if (this.textAreaValue.length < 1) {
              this.$refs.toast.show({
                message: this.i18n.t('discuzq.post.theContentCanNotBeBlank')
              }); //~内容不能为空
              status = false;
            }
            // else if (Number(this.priceAsk) < Number(this.forums.other.can_be_asked_money)) {
            //     this.$refs.toast.show({ message: `打赏金额不能低于${this.forums.other.can_be_asked_money}元` });
            // }
            else if (this.watchShow) {
              //如果显示他人围观
              this.payShowStatus = true;
              this.$nextTick(() => {
                this.$refs.payShow.payClickShow();
              });
            }
            break;
          case 6:
            if (this.dataGoodInfo === '' || this.dataGoodInfo.length === 0) {
              this.$refs.toast.show({
                message: this.i18n.t('core.productInformationDoesNotExist')
              }); //~商品信息不存在
              status = false;
            } else {
              status = true;
            }
            break;
          default:
            status = false;
            this.$refs.toast.show({
              message: this.i18n.t('core.postTypesDoNotMatch')
            }); //~帖子类型不匹配，请重新进入本页面
        }

        if (status) {
          this.save = true;
          clearInterval(this.timer1);
          this.timer1 = null;
          clearInterval(this.timer2);
          this.timer2 = null;
          // 定时器消除成功
          if (this.type !== 5) {
            this.postLoading = true;
            // uni.showLoading();
          }
          if (this.operating === 'edit') {
            if (this.type === 3) {
              if (this.uploadFile.length < 1) {
                this.$refs.toast.show({
                  message: this.i18n.t('discuzq.post.imageCannotBeEmpty'), //~图片不能为空
                });
                uni.hideLoading();
                this.postLoading = false;
              } else {
                this.editThread().then(res => {
                  this.postLoading = false;
                  uni.hideLoading();
                  if (res && this.threadId) {
                    uni.redirectTo({
                      url: `/topic/index?id=${this.threadId}`,
                    });
                  }
                });
              }
            } else {
              this.editThread().then(res => {
                this.postLoading = false;
                uni.hideLoading();
                // uni.navigateBack({
                //   delta: 1,
                // });
                if (res && this.threadId) {
                  uni.redirectTo({
                    url: `/topic/index?id=${this.threadId}`,
                  });
                }
              });
            }
          } else {
            if (this.forums.qcloud.qcloud_captcha && this.forums.other.create_thread_with_captcha) {
              if (!this.ticket || !this.randstr) {
                this.toTCaptcha();
                return false;
              }
            }
            if (!this.watchShow || this.type !== 5) {
              if (this.is_red_packet === 1 || this.is_red_packet === '1') {
                this.$nextTick(() => {
                  this.$refs.payShowtwo.payClickShow();
                });
              } else {
                this.postThread().then(res => {
                  // #ifdef MP-WEIXIN
                 this.getTemplates({
                   type_name:'内容审核通过通知'
                 });
                 // #endif
                  this.postLoading = false;
                  uni.hideLoading();
                  if (res && res.isApproved === 1) {
                    this.$u.event.$emit('addThread', res);
                  }
                  if (res && res.Data && res.Data.id) {
                    uni.redirectTo({
                      url: `/topic/index?id=${res.Data.id}`,
                    });
                  }
                });
              }
            }
          }
        }
      },


      // 编辑回显主题，处理附件
      setAnnex(type, data) {
        switch (type) {
          case 'img':
            let filePreview = [];
            data.firstPost.images.map(item => {
              filePreview.push({
                path: item.thumbUrl,
                id: item._jv.id,
                order: item.order,
                name: item.fileName,
                url: item.url,
              });
              return item;
            });
            this.filePreview = filePreview;
            break;
          case 'video':
            this.videoBeforeList.push({
              path: data.threadVideo.media_url,
            });
            // this.videoPercent = 1;
            break;
          case 'audio':
            this.audioBeforeList.push({
              fileName: data.threadAudio.file_name,
              url: data.threadAudio.media_url,
              id: data.threadAudio.file_id,
            });
            break;
          case 'goods':
            this.dataGoodInfo = data.firstPost.postGoods;
            if (
              data.firstPost.postGoods.price.indexOf('-') !== -1 ||
              Number(data.firstPost.postGoods.price) > 0
            ) {
              this.dataGoodInfoPrice = data.firstPost.postGoods.price;
            } else if (Number(data.firstPost.postGoods.price) <= 0) {
              this.dataGoodInfoPrice = '';
            }
            // this.audioBeforeList.push({
            //   fileName: data.threadAudio.file_name,
            //   url: data.threadAudio.media_url,
            //   id: data.threadAudio.file_id,
            // });
            break;
          default:
            break;
        }
      },
      // 发布主题，处理图片
      addImg() {
        const attachments = {};
        attachments.data = [];
        this.uploadFile.forEach(item => {
          if (item) {
            attachments.data.push({
              type: 'attachments',
              id: item.id,
            });
          }
        });
        return attachments;
      },
      // 发布主题，处理附件
      addFile() {
        const attachmentFiles = {};
        attachmentFiles.data = [];
        // if (this.type === 1 && this.$refs.uploadFiles) {
        const newAttachmentList = this.$refs.uploadFiles.getValue();
        newAttachmentList.forEach(item => {
          if (item.id) {
            attachmentFiles.data.push({
              type: 'attachments',
              id: item.id,
            });
          }
        });
        // }
        return attachmentFiles;
      },
      // 发布问题
      addQuestion() {
        const question = {
          data: {
            be_user_id: this.beAskId,
            price: this.priceAsk,
            is_onlooker: this.watchChecked,
            order_id: this.orderSn,
            type: 1,
          },
        };
        // if(!this.watchShow){
        //   delete question.data.order_id
        // }
        return question;
      },
      // 删除附件显示弹框
      deleteFile(id) {
        this.deleteTip = this.i18n.t('core.deleteEnclosureSure');
        this.$refs.deletePopup.open();
        this.deleteType = 1;
        this.deleteId = id;
      },
      // 删除附件调用删除接口
      deleteFileSure(id) {
        const params = {
          _jv: {
            type: 'attachments',
            id,
          },
        };
        this.$store.dispatch('jv/delete', params).then(res => {
          this.$refs.uploadFiles.deleteSure();
        });
      },
      // 接口请求
      async getCategories() {
        await this.$store.dispatch('jv/get', ['categories.v2?filter[createThread]=1', {}]).then(res => {
          res = res._jv.json.Data;
          this.allCategories = res;

          // #ifndef H5 || MP-WEIXIN || APP-PLUS
          res.map(item => {
            if (item) {
              if (Number(item.pid) === Number(this.categoryId)) {
                this.checkClassData.push(item);
              }
            }
            return item;
          });
          // #endif
        });

        !!this.categoryId && this.initCategoryId(this.categoryId);

      },
      //分类回显的方法
      initCategoryId(categoryId) {
        // 回显时候获取的参数
        this.allCategories.forEach(item => {
          if (item.pid == categoryId) {
            this.categoryId = categoryId;
            this.two_categoryId = '';
          } else {
            item.children &&
              item.children.forEach(c => {
                if (c.id == categoryId) {
                  this.secondallcategories = item.children;
                  this.categoryId = Number(item.pid);
                  this.two_categoryId = categoryId;
                }
              });
          }
        });
      },
      postThread() {

        let self = this;
        const sun = {
          categoriesId: Number(this.thread_id),
          categoryName:this.thread_name,
          content: this.textAreaValue,
          type: this.type,
          isAnonymous: this.checked ? 1 : 0,
          price: Number(this.price),
          freeWords: this.word,
          id: this.currentId,
          isDraft: 0,
          isOldDraft: this.currentId ? 1 : 0,
          captchaTicket: this.ticket,
          captchaRandStr: this.randstr,
          redPacket: {
            rule: +this.rule,
            money: +this.money,
            number: +this.number,
            condition: +this.condition,
            likenum: +this.likenum,
            orderId: this.orderSn,
            orderPrice: 0,
          },
        };

        if (this.payType === 1) {
          sun.attachmentPrice = this.price;
          sun.price = 0;
        } else if (this.payType === 0) {
          sun.attachmentPrice = '';
          sun.price = Number(this.price);
        }
        const currentPositions = this.currentPosition;

        if (currentPositions) {
          sun.longitude = Number(currentPositions.longitude) || '';
          sun.latitude = Number(currentPositions.latitude) || '';
          sun.location = currentPositions.location || '';
          sun.address = currentPositions.address || '';
        } else {
          //异步取不到值，以后修改吧
          uni.getLocation({
            type: 'wgs84',
            success: function(res) {
              sun.longitude=res.longitude||'';
              sun.latitude= res.latitude||'';
              sun.address =res.address ||''
            }
          });
        }

        const postPromise = new Promise((resolve, reject) => {
          switch (this.type) {
            case 0:
              resolve();
              break;
            case 1:
              sun.title = this.postTitle;
              const num = this.addImg().data.concat(this.addFile().data);
              sun.attachments = []
              num.map(item => {
                sun.attachments.push({
                  id: Number(item.id),
                  type: item.type
                });
              });
              resolve();
              break;
            case 2:
              sun.fileId = this.fileId;
              sun.fileName = this.videoName;
              resolve();
              break;
            case 3:
              const numImg = this.addImg().data;
              sun.attachments = [];
              numImg.map(item => {
                sun.attachments.push({
                  id: Number(item.id),
                  type: item.type
                });
              });
              resolve();
              break;
            case 4:
              sun.fileId = this.audioBeforeList[0].id;
              sun.fileName = this.audioBeforeList[0].fileName;
              resolve();
              break;
            case 5:
              const askNum = this.addImg().data;
              const askQuestion = this.addQuestion().data;
              sun.attachments = [];
              sun.question = {};
              askNum.map(item => {
                sun.attachments.push({
                  id: Number(item.id),
                  type: item.type
                });
              })
              if (askQuestion) {
                sun.question.type = askQuestion.type;
                sun.question.price = Number(askQuestion.price);
                sun.question.orderId = askQuestion.order_id;
                sun.question.isOnlooker = askQuestion.is_onlooker;
                sun.question.beUserId = askQuestion.be_user_id;
              }
              resolve();
              break;
            case 6:
              sun.postGoodsId = Number(this.dataGoodInfo._jv.id);
              resolve();
              break;
            default:
              reject();
              this.$refs.toast.show({
                message: this.i18n.t('core.postTypesDoNotMatch')
              });
          }
        });
        this.save = true;
        clearInterval(this.timer1);
        this.timer1 = null;
        clearInterval(this.timer2);
        this.timer2 = null;
        if(this.Submiting)
        {
          return;
        }
        this.Submiting=true;

        return postPromise.then(() => {
          return apiRequest.createThread({
              data: sun
            })
            .then((res) => {
              self.videoBeforeList = [];
              self.Submiting=false
              return res
            })
            .catch(err => {
              self.Submiting=false
              console.log(err);
            });
        });
      },

      delAttachments(id, index) {
        if (this.operating === 'edit') {
          this.$u.event.$emit('deleteImg', {
            threadId: this.postDetails._jv.id,
            index,
          });
          const post = this.$store.getters['jv/get'](`posts/${this.postDetails.firstPost._jv.id}`);
          post.images.splice(index, 1);
          post._jv.relationships.images.data.splice(index, 1);
        }
      },
      handleClickOk() {
        this.$refs.deletePopup.close();
        if (this.deleteType === 0) {
          // 删除类型为图片
          this.delAttachments(this.deleteId, this.deleteIndex);
          this.$refs.upload.clear(this.deleteIndex);
          // this.delAttachments(this.deleteId, this.deleteIndex).then(() => {
          //   this.$refs.upload.clear(this.deleteIndex);
          // });
        } else if (this.deleteType === 2) {
          // 删除类型为视频
          this.videoBeforeList = [];
          this.percent = 0;
          // this.videoPercent = 0;
        } else if (this.deleteType === 3) {
          this.audioBeforeList = [];
        }
      },
      handleClickCancel() {
        this.$refs.deletePopup.close();
      },
      // 确认去绑定微信
      handleWechatClickOk() {
        // #ifdef MP-WEIXIN
        this.mpLogin();
        // #endif
        // #ifdef H5|| APP-PLUS
        if (this.isWeixin) {
          this.wxh5Login(0, 0);
        } else {
          uni.showToast({
            icon: 'none',
            title: this.i18n.t('user.unLogin'), //~由于手机浏览器的限制，请在微信内使用此功能
            duration: 2000,
          });
        }
        // #endif
      },
      // 取消去绑定微信
      handleWechatClickCancel() {
        this.$refs.wechatPopup.close();
      },
      getSignature(callBack) {
        this.$store.dispatch('jv/get', ['signature', {}]).then(res => {
          // #ifndef MP-WEIXIN
          callBack(() => res.signature);
          // #endif
          // #ifdef MP-WEIXIN
          callBack(res.signature);
          // #endif
        });
      },
      postVideo(fileId) {
        const params = {
          _jv: {
            type: 'thread/video',
          },
          file_id: fileId,
          type: 0,
        };
        this.$store.dispatch('jv/post', params);
      },
      // 获取当前编辑的主题数据
      getPostThread(option) {
        const params = {
          include: [
            'firstPost',
            'firstPost.images',
            'threadVideo',
            'threadAudio',
            'category',
            'firstPost.attachments',
            'question',
            'onlookers',
            'question.beUser',
            'question.images',
            'firstPost.postGoods',
          ],
        };
        this.$store.dispatch('jv/get', [`threads/${this.threadId}`, {
          params
        }]).then(res => {
          this.is_red_packet = res.isRedPacket;
          if (res.question) {
            this.beUserName = res.question.beUser.username;
            this.beAskId = res.question.beUser.id;
            this.userImage = res.question.beUser.avatarUrl;
          }
          this.postDetails = res;
          this.firstPostId = res.firstPost._jv.id;
          this.type = res.type;

          // #ifdef MP-WEIXIN
          this.markdownShow = false;
          // #endif
          // #ifdef H5|| APP-PLUS
          if (this.type === 1) {
            this.markdownShow = true;
          }
          // #endif

          this.attachmentList = Object.values(res.firstPost.attachments) || [];
          this.textAreaValue = res.firstPost.parseContentHtml;
          this.categoryId = res.category._jv.id;
          this.initCategoryId(this.categoryId);
          this.checkClassData.push(res.category);
          if (res.threadVideo) {
            this.fileId = res.threadVideo.file_id;
            this.percent = 1;
          }
          //问答匿名和围观回显
          this.checked = res.isAnonymous;
          if (this.type === 5) {
            this.watchChecked = res.question.is_onlooker;
          }
          // this.uploadFile = res.firstPost.images;
          if (res.firstPost.images) {
            let images = Object.values(res.firstPost.images)
            images.forEach(item => {
              if (item) {
                this.uploadFile.push({
                  type: 'attachments',
                  id: item._jv.id,
                  order: item.order,
                  name: item.fileName,
                  url: item.url,
                  path: item.thumbUrl ? item.thumbUrl : '',
                });
              }
            });
          }
          if (this.type === 6 && res.firstPost.postGoods) {
             this.dataGoodInfo = res.firstPost.postGoods;
            if (
              res.firstPost.postGoods.price.indexOf('-') !== -1 ||
              Number(res.firstPost.postGoods.price) > 0
            ) {
              this.dataGoodInfoPrice = res.firstPost.postGoods.price;
            } else if (Number(res.firstPost.postGoods.price) <= 0) {
              this.dataGoodInfoPrice = '';
            }

            this.isShowGoods = true;
          }
          this.loadStatus = true;
          if (Number(res.price) > 0) {
            this.price = res.price;
            this.word = res.freeWords;
            this.freepercentage.forEach(item => {
              if (res.freeWords === item.pay) {
                this.percentagedisplay = item.name;
              }
            });
            this.payType = 2;
            this.showPayType = this.i18n.t('discuzq.post.TheContentAndTheAccessoriesIsPaid');
            if (this.type === 1) {
              this.payNum[0].name = '￥1';
              this.payNum[0].pay = 1;
            }
          } else if (Number(res.attachmentPrice) > 0) {
            this.price = res.attachmentPrice;
            this.payType = 1;
            this.showPayType = this.i18n.t('discuzq.post.TheContentIsFreeAndTheAccessoriesArePaid');
            this.payNum[0].name = '￥1';
            this.payNum[0].pay = 1;
          } else {
            this.showPayType = this.i18n.t('discuzq.post.TheContentAndTheAccessoriesIsFree');
          }

          this.textAreaLength = this.type === 1 ? 49999 : 5000;
          switch (Number(res.type)) {
            case 0:
              break;
            case 1:
              this.postTitle = res.title;
              this.setAnnex('img', res);
              break;
            case 2:
              this.percent = 1;
              this.setAnnex('video', res);
              break;
            case 3:
              this.setAnnex('img', res);
              break;
            case 4:
              this.setAnnex('audio', res);
              break;
            case 5:
              this.setAnnex('img', res);
              break;
            case 6:
              this.setAnnex('goods', res);
              break;
            default:
          }
          // 微信里面的定位
          if (option.name) {
            let currentPosition = {};
            const data = option.latng.split(',');
            currentPosition.longitude = data[1];
            currentPosition.latitude = data[0];
            currentPosition.location = option.name;
            currentPosition.address = option.addr;
            this.currentPosition = currentPosition;
          } else {
            this.currentPosition.longitude = res.longitude || '';
            this.currentPosition.latitude = res.latitude || '';
            this.currentPosition.location = res.location || '';
            this.currentPosition.address = res.address || '';
          }
          if (this.operating === 'edit' && this.goodsId) {
            this.getGoodsInfo();
          }
          this.setThread();
        });
      },

      // 获取商品信息
      getGoodsInfo() {
        this.$store.dispatch('jv/get', `goods/${this.goodsId}`).then(res => {

          // 这是取到的商品信息
          this.dataGoodInfo = res;
          if (res.price.indexOf('-') !== -1 || Number(res.price) > 0) {
            this.dataGoodInfoPrice = res.price;
          } else if (Number(res.price) <= 0) {
            this.dataGoodInfoPrice = '';
          }
          this.isShowGoods = true;
        });
      },

      // 编辑帖子接口
      async editThread() {
        let state = 0;
        const postNum = {
          pid: Number(this.firstPostId),
          data: {
            attributes: {
              content: this.textAreaValue,
              is_old_draft: 1,
            },
            relationships: {
              attachments: {
                data: [],
              },
            },
            id: Number(this.threadId),
          }
        };
        const threadsNum = {
          categoriesId: Number(this.thread_id),
          id: Number(this.threadId),
          isOldDraft: 1,
          content: this.textAreaValue,
          type: this.type,
        }
        const currentPositions = this.currentPosition;
        threadsNum.longitude = Number(currentPositions.longitude) || '';
        threadsNum.latitude = Number(currentPositions.latitude) || '';
        threadsNum.location = currentPositions.location || '';
        threadsNum.address = currentPositions.address || '';
        switch (this.type) {
          case 0:
            break;
          case 1:
            threadsNum.title = this.postTitle;
            if (this.payType === 1) {
              threadsNum.attachmentPrice = this.price;
              threadsNum.price = 0;
            } else if (this.payType === 2) {
              threadsNum.attachmentPrice = '';
              threadsNum.price = Number(this.price);
            } else if (this.payType === 0) {
              threadsNum.attachmentPrice = 0;
              threadsNum.price = 0;
            }
            const num = this.addImg().data.concat(this.addFile().data);
            postNum.data.relationships.attachments.data = [];
            num.forEach(item => {
              postNum.data.relationships.attachments.data.push({
                id: Number(item.id),
                type: item.type
              });
            })
            break;
          case 2:
            threadsNum.fileId = this.fileId;
            threadsNum.fileName = this.videoName;
            threadsNum.price = this.price;
            break;
          case 3:
            threadsNum.price = this.price;
            const numImg = this.addImg().data;
            postNum.data.relationships.attachments.data = [];
            numImg.forEach(item => {
              postNum.data.relationships.attachments.data.push({
                id: Number(item.id),
                type: item.type
              });
            })
            break;
          case 4:
            threadsNum.price = this.price;
            threadsNum.fileId = this.audioBeforeList[0].id;
            threadsNum.fileName = this.audioBeforeList[0].fileName;
            break;
          case 5:
            const askNum = this.addImg().data;
            postNum.data.relationships.attachments.data = [];
            askNum.forEach(item => {
              postNum.data.relationships.attachments.data.push({
                id: Number(item.id),
                type: item.type
              });
            })
            params._jv.relationships.question = this.addQuestion();
            break;
          case 6:
            postNum.postGoodsId = this.dataGoodInfo._jv.id;
            break;
          default:
            break;
        }
        await apiRequest.updatePosts({
          data: postNum
        }).then(res => {
          if (res.Data.pid) state += 1;
          return res;
        });
        await apiRequest.updateThreads({
            data: threadsNum
          })
          .then((res) => {
            if (res.Data.id) state += 1;
          })
        if (state === 2) {
          return state;
        }
        throw new Error('出错了');
      },
      // 小程序内发布按钮验证码验证
      toTCaptcha() {
        // #ifdef MP-WEIXIN
        let _this = this;
        wx.navigateToMiniProgram({
          appId: 'wx5a3a7366fd07e119',
          path: '/pages/captcha/index',
          envVersion: 'release',
          extraData: {
            appId: this.forums.qcloud.qcloud_captcha_app_id, //您申请的验证码的 appId
          },
          success(res) {
            // 验证码成功打开
            _this.payShowStatus = true; //如果成功显示支付收银台
          },
          fail(err) {
            uni.hideLoading();
            _this.postLoading = false;
            _this.payShowStatus = false;
          },
        });
        // #endif
        // h5内发布按钮验证码验证
        // #ifdef H5|| APP-PLUS
        this.captcha = new TencentCaptcha(this.forums.qcloud.qcloud_captcha_app_id, res => {
          if (res.ret === 0) {
            this.ticket = res.ticket;
            this.randstr = res.randstr;
            this.payShowStatus = true; //如果成功显示支付收银台
            // 验证通过后发布
            this.postClick();
          }
          if (res.ret === 2) {
            this.postLoading = false;
            this.payShowStatus = false;
            uni.hideLoading();
          }
        });
        // 显示验证码
        this.captcha.show();
        // #endif
      },
      // 问答贴点击头像跳转选择被提问人
      changeAvatar() {
        const _this = this;
        uni.setStorage({
          key: 'edit_content',
          data: _this.textAreaValue,
        });
        uni.navigateTo({
          url: '/pages/user/at-member?name=select'
        });
      },
    },

    onLoad(option) {
      this.getData()


      this.url = DISCUZ_REQUEST_HOST;
      // 页面传参
      if (option.isSaveText === '1') {
        try {
          // 取回用户编辑的文本
          const value = uni.getStorageSync('add_goods_text');
          if (value) {
            this.textAreaValue = value;
          }
        } catch (e) {}
      }

      // 监听页面加载，其参数为上个页面传递的数据，参数类型为Object（用于页面传参）
      if (option.operating === 'edit') {
        this.cansavedraft = false;
        this.redbagplay = false;
      } //是否开启自动保存
      this.currentId = option.threadId;
      if (option.isredbag == 1) {
        this.$store.dispatch('jv/get', [`redpacket/${option.threadId}`, {}]).then(
          data => {
            // 红包轮询
            this.is_red_packet = option.isredbag;
            this.money = data.money;
            this.showmoney = data.money;
            this.number = data.number;
            this.condition = data.condition;
            this.likenum = data.likenum;
            this.rule = data.rule;
            if (this.rule === '1' || this.rule === 1) {
              this.sumtype = '随机';
            } else {
              this.sumtype = '固定';
              this.showmoney = this.money / this.number;
            }
          },
          err => console.log(err),
        );
      }
      if (option.type === '5') {
        uni.getStorage({
          key: 'edit_content',
          success: res => {
            this.textAreaValue = res.data;
          },
        });
        this.payNum[0].name = this.i18n.t('discuzq.post.noReward'); //~不打赏
      }

      // this.lowestPrice = option.lowestPrice || 0; // 最低打赏价格
      this.categoryid = option.categoryId; //分类id会等于传进来的id
      this.categoryindex = option.categoryIndex; //与支付相关的，设置本地字段的一个属性
      uni.$on('radioChange', item => {
        this.beUserName = item.username; //被提问用户的用户名会等于item实参底下的这个
        this.beAskId = item.id; //被提问人ID会等于item实参底下的这个
        this.userImage = item.avatarUrl; // 被提问用户的头像
      });
      if (this.forums && this.forums.other) {
        this.canUploadAttachment = this.forums.other.can_upload_attachments; // 用户上传附件权限
      }
      // 问答编辑不显示提问价格
      if (this.forums && this.forums.paycenter) {
        if (option.operating === 'edit' || !this.forums.paycenter.wxpay_close) {
          this.askingPrice = false;
        } else {
          // 初始化默认内容附件均免费
          this.showPayType = this.i18n.t('discuzq.post.TheContentAndTheAccessoriesIsFree');
        }
      }

      if (option.type) this.type = Number(option.type);
      // #ifdef MP-WEIXIN
      const data = uni.getSystemInfoSync();
      if (data.platform === 'ios' && this.type === 5) {
        this.askingPrice = false;
        // this.postClick = true;
      }
      // #endif
      // #ifdef H5
      const {
        isWeixin
      } = appCommonH.isWeixin();
      this.isWeixin = isWeixin;
      this.isPhone = appCommonH.isWeixin().isPhone; // 这是h5
      if (this.isWeixin === false) {
        this.payTypeData[0].hide = true;
      }
      this.browser = 1;
      if (this.type === 1) {
        //重显示的文字
        uni.$on('vditor', (vditor, vditorComponent) => {
          this.vditor = vditor;
          this.vditor.setValue(this.textAreaValue);
          vditorComponent.setPostComponent(this);
        });
      }
      // #endif

      const token = uni.getStorageSync('access_token');
      this.header = {
        authorization: `Bearer ${token}`,
      };
      this.formData = {
        type: 1,
      };
      this.getCategories();

      if (option.operating) this.operating = option.operating;
      if (option.threadId) this.threadId = option.threadId;
      if (option.categoryIndex) {
        if (option.categoryIndex === '0') {
          this.categoryIndex = '';
        } else {
          this.categoryIndex = Number(option.categoryIndex);
        }
      }

      if (option.categoryId)
        this.categoryId = Number(option.categoryId) === 0 ? '' : Number(option.categoryId);
      this.textAreaLength = Number(option.type) === 1 ? 49999 : 5000;

      if (this.operating === 'edit' || this.operating === 'draft') {
        this.loadStatus = false;
        this.getPostThread(option);
      } else {
        this.loadStatus = true;
        if (option.name) {
          let currentPosition = {};
          const data = option.latng.split(',');
          currentPosition.longitude = data[1];
          currentPosition.latitude = data[0];
          currentPosition.location = option.name;
          currentPosition.address = option.addr;
          this.currentPosition = currentPosition;
        }
      }

      try {
        const res = uni.getSystemInfoSync();
        if (

          this.forums &&
          this.forums.paycenter.wxpay_close &&
          this.forums.other.can_create_thread_paid
        ) {
          // #ifndef H5
          if (res.platform === 'ios') {
            // if (this.forums.paycenter.wxpay_ios === false) {
            //   this.showHidden = false;
            // } else {
            //   this.showHidden = true;
            // }
            this.ioshide = false;
          } else {
            this.ioshide = true;
            this.showHidden = true;
          }
          // #endif
          // #ifdef H5
          this.ioshide = true;
          this.showHidden = true;
          // #endif
        } else {
          this.ioshide = false;
          this.showHidden = false;
        }
      } catch (e) {
        // error
        console.log(e)
      }

      // #ifdef MP-WEIXIN
      this.markdownShow = false;
      // #endif
      // #ifdef H5|| APP-PLUS
      if (this.type === 1) {
        this.markdownShow = true;
      }
      // #endif
      // 接受验证码captchaResult
      this.$u.event.$on('captchaResult', result => {
        this.ticket = result.ticket;
        this.randstr = result.randstr;
        this.postClick();
      });
      this.$u.event.$on('closeChaReault', () => {
        this.postLoading = false;
        this.payShowStatus = false;
        uni.hideLoading();
      });

      uni.$on('clickTopic', data => {
        if (data.keywords)
          this.textAreaValue = `${this.textAreaValue.slice(0, this.cursor)}  #${data.keywords.replace(
          /\s+/g,
          '',
        )}#${this.textAreaValue.slice(this.cursor)}  `;
        this.cursor = this.textAreaValue ? this.textAreaValue.length : 0;
      });
      if (this.type === 6) {
        this.goodsId = option.goodsId;
      }
      if (
        (this.type === 6 && option.operating !== 'edit' && option.threadId !== '' && this.goodsId) ||
        (this.type === 6 && this.goodsId)
      ) {
        this.getGoodsInfo();
      }

      // 接收来自首页的数据，并渲染或者报错时提示
      if (this.type === 2 || this.type === 3) {

        const eventChannel = this.getOpenerEventChannel();

        eventChannel.on('acceptDataFromOpenerPage', attachments => {

          if (this.type === 3) {

            attachments.map(item => {
              // eslint-disable-next-line
              // 当首页上传图片成功时
              this.uploadFile.push({
                type: 'attachments',
                id: item.data.id,
                order: item.data.attributes.order,
                name: item.data.attributes.fileName,
                url: item.data.attributes.url,
                path: item.data.attributes.thumbUrl ? item.data.attributes.thumbUrl : '',
              });
              this.filePreview.push({
                path: item.data.attributes.thumbUrl,
                id: item.data.id,
                order: item.data.attributes.order,
                name: item.data.attributes.fileName,
                url: item.data.attributes.url,
              });

            });
            this.addImg();
          }
          if (this.type === 2) {
            if (attachments.data) {
              if (attachments.data.doneResult) {
                this.fileId = attachments.data.doneResult.fileId;
                this.videoName = attachments.data.uploadVideoRes.name;
              } else {
                this.fileId = attachments.data.result.fileId;
              }
              this.videoBeforeList.push({
                path: attachments.data.uploadVideoRes.tempFilePath,
              });
              this.chooseType = 0;
              this.percent = 1;
            }
          }
        });
      }
      if (option.fromdrafts) {
        this.operating = '';
      }

    },
    onShow() {
      //监听页面显示。页面每次出现在屏幕上都触发，包括从下级页面点返回露出当前页面
      let atMemberList = '';
      this.getAtMemberData.map(item => {
        atMemberList += `@${item.username} `;
        return atMemberList;
      });
      this.textAreaValue = `${this.textAreaValue.slice(0, this.cursor) +
      atMemberList +
      this.textAreaValue.slice(this.cursor)}`;
      this.setAtMember([]);
      this.cursor = this.textAreaValue ? this.textAreaValue.length : 0;
      if (!this.threadId) {
        this.setThread();
      }
      // 初次渲染拿到这些值
      uni.getStorage({
        key: 'is_red_packet',
        success: res => {
          this.is_red_packet = res.data;
        },
      });
      uni.getStorage({
        key: 'rule',
        success: res => {
          this.rule = res.data;
        },
      });
      uni.getStorage({
        key: 'money',
        success: res => {
          this.money = res.data;
          this.showmoney = res.data;
        },
      });
      uni.getStorage({
        key: 'number',
        success: res => {
          this.number = res.data;
        },
      });
      uni.getStorage({
        key: 'condition',
        success: res => {
          this.condition = res.data;
        },
      });
      uni.getStorage({
        key: 'likenum',
        success: res => {
          this.likenum = res.data;
          if (this.rule === '1' || this.rule === 1) {
            this.sumtype = '随机';
          } else {
            this.sumtype = '固定';
            this.money = this.money * this.number;
          }
        },
      });
    },
    onReady() {
      //监听页面初次渲染完成
      this.videoContext = uni.createVideoContext('video');
    },
    onUnload() {
      //监听页面卸载
      this.$u.event.$off('captchaResult');
      this.$u.event.$off('closeChaReault');
      this.$u.event.$off('radioChange');
      this.$u.event.$off('radioEditChange');
      // #ifdef H5|| APP-PLUS
      uni.$off('clickTopic');
      uni.$off('clickImage');
      uni.$off('clickAttach');
      // #endif
      // 隐藏验证码
      if (this.captcha) {
        this.captcha.destroy();
      }
      clearInterval(payWechat);
      clearInterval(payPhone);
      uni.removeStorage({
        key: 'is_red_packet',
        success: res => {},
      });
      uni.removeStorage({
        key: 'rule',
        success: res => {},
      });
      uni.removeStorage({
        key: 'money',
        success: res => {},
      });
      uni.removeStorage({
        key: 'number',
        success: res => {},
      });
      uni.removeStorage({
        key: 'condition',
        success: res => {},
      });
      uni.removeStorage({
        key: 'likenum',
        success: res => {},
      });
      uni.removeStorage({
        key: 'edit_content',
        success: res => {},
      });
      this.save = true;
      clearInterval(this.timer1);
      this.timer1 = null;
      clearInterval(this.timer2);
      this.timer2 = null;
    },
    mounted() {
      // 监听自动保存
      if (this.cansavedraft) {
        this.onStartSave();
      }
      this.red_bagshow();
      this.geographical_location_show();
    },
  };
</script>

<style lang="scss" scoped>
  @import '@/styles/base/theme/fn.scss';
  @import '@/styles/base/variable/global.scss';

  /* #ifdef H5 || MP-WEIXIN || APP-PLUS */
  .uni-list-cell-gw {
    display: flex;
    flex-direction: column;
  }

  .uni-list-cell-gw-explain {
    font-size: 24rpx;
    color: #c5c6cb;
  }

  /* #endif */
  .post-box {
    width: 100vw;
    height: 100%;
    padding: 40rpx;
    overflow: auto;
    background-color: --color(--qui-BG-2);
    box-sizing: border-box;

    &__title {
      display: flex;
      align-items: center;
      width: 100vw;
      height: 100rpx;
      margin-bottom: 30rpx;
      border-bottom: 2rpx solid --color(--qui-BOR-ED);

      &-input {
        width: 100%;
        padding-right: 80rpx;
        font-size: $fg-f5;
      }
    }

    &__titles {
      margin-bottom: 30rpx;
    }

    &__hd {
      display: flex;
      justify-content: space-between;
      align-items: center;

      &-l {
        &__icon {
          margin-right: 54rpx;
        }
      }

      &-r {
        font-size: $fg-f2;
        color: --color(--qui-FC-777);
        /* #ifdef H5 || MP-WEIXIN || APP-PLUS */
        color: #999 !important;
        /* #endif */
      }
    }

    &__con {
      width: 100%;
      // max-height: 900rpx;
      /* #ifdef H5 || MP-WEIXIN */
      max-height: 900rpx;
      /* #endif */
      padding: 10rpx 0 0;
      margin-top: 20rpx;
      /* #ifdef H5 || MP-WEIXIN */
      margin-bottom: 63rpx;
      /* #endif */
      overflow: hidden;
      background-color: --color(--qui-BG-1);
      border: 1rpx solid --color(--qui-BOR-DDD);
      border-radius: 7rpx;
      box-sizing: border-box;
    }

    &__con-text {
      z-index: 0;
      width: 100%;
      max-height: 900rpx;
      min-height: 400rpx;
      /* #ifdef H5 || MP-WEIXIN */
      min-height: 238rpx;
      /* #endif */
      padding: 10rpx 20rpx 20rpx;
      font-size: $fg-f4;
      line-height: 40rpx;
      box-sizing: border-box;

      .text-cover {
        font-size: $fg-f4;
        line-height: 40rpx;
      }

      &--static {
        overflow: auto;
      }
    }

    &__ft {
      &-tit {
        display: block;
        margin: 30rpx 0;
        font-size: $fg-f4;
        color: --color(--qui-FC-7D7979);
      }

      &-categories {
        // 分类下面的margin
        margin-bottom: 40rpx;
      }
    }

    &__good {
      display: flex;
      flex-direction: row;
      justify-content: flex-start;
      margin: 30rpx 0;
      font-size: $fg-f3;

      &__image {
        width: 160rpx;
        height: 160rpx;
        margin: 0 30rpx 0 0;
        border-radius: 5rpx;
      }

      &__info {
        position: relative;
        flex: 1;
        display: flex;
        flex-direction: column;
      }

      &__title {
        max-height: 120rpx;
        overflow: hidden;
        font-weight: bold;
        line-height: 40rpx;
        color: --color(--qui-FC-333);
      }

      &__ft {
        position: absolute;
        bottom: 0;
        display: flex;
        width: 100%;
        justify-content: space-between;
        align-items: center;
        line-height: 45rpx;
        color: --color(--qui-FC-777);
      }

      &__price {
        display: inline-block;
        font-size: $fg-f5;
        color: --color(--qui-RED);
      }

      &__btn {
        display: inline-block;
      }
    }

    &__space {
      width: 100%;
      height: 160rpx;
      margin: 30rpx 0;
      line-height: 160rpx;
      color: --color(--qui-FC-B5);
      text-align: center;
      background-color: --color(--qui-FC-f7);
      border: 1rpx solid --color(--qui-BOR-ED);
      border-radius: 5rpx;
    }

    &__position /deep/ {
      position: relative;
      color: --color(--qui-FC-777);

      .icon-weizhi {
        margin-right: 10rpx;
      }

      .icon-close1 {
        position: absolute;
        top: 36rpx;
        right: 0;
        z-index: 100;
      }
    }
  }

  .play-load {
    .post-box__video__play__load__mask {
      position: absolute;
      width: 100%;
      height: 100%;
      background-color: --color(--qui-BG-ED);
      border: 1px solid --color(--qui-BOR-ED);
      border-radius: 5rpx;
      opacity: 0.7;
    }

    .post-box__video__play__load__text {
      position: relative;
      z-index: 2;
      font-size: $fg-f4;
      line-height: 36rpx;
      color: --color(--qui-FC-34);
    }

    progress {
      position: absolute;
      bottom: 9.5rpx;
      z-index: 3;
      width: 87.5%;
    }
  }

  .post-box__ft-categories /deep/ .qui-button--button {
    margin-top: 10rpx;
    margin-right: 20rpx;
    margin-bottom: 10rpx;

    &[size='default'] {
      /* #ifndef H5 || MP-WEIXIN */
      border: 1px solid rgba(0, 0, 0, 0.2);
      /* #endif */
    }

    /* #ifdef H5 ||MP-WEIXIN */
    &[type='primary'] {
      color: #fff;
      background: #ea3d5a;
      border: none;
    }

    /* #endif */
  }

  .post-box__ft-categories /deep/ .qui-button--button:after {
    border: none;
    border-radius: 0;
  }

  .post-box__ft-categories /deep/ .cateActive {

    // 分类按钮点击时候变化颜色
    &[size='default'] {
      /* #ifdef H5 || MP-WEIXIN */
      color: #fff;
      background: #ea3d5a;
      border: none;
      /* #endif */
      /* #ifndef H5 || MP-WEIXIN */
      border: 1px solid #1878f3;
      /* #endif */
    }
  }

  .popup-content-btn {
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;

    .popup-btn {
      margin-top: 20rpx;
    }
  }

  .popup-share {
    /* #ifndef APP-NVUE */
    display: flex;
    flex-direction: column;
    /* #endif */
    background: --color(--qui-BG-2);
  }

  .popup-share-content {
    height: 477rpx;
    padding: 40rpx 45rpx;
    text-align: center;
    box-sizing: border-box;

    .popup-title {
      font-size: $fg-f4;
    }
  }

  .popup-share-content-space {
    width: 100%;
    height: 9rpx;
    background: --color(--qui-BG-ED);
  }

  .emoji-bd {
    position: relative;
    width: 100%;
  }

  /deep/ textarea .textarea-placeholder {
    // 输入框的字体
    font-size: $fg-f4;
    color: --color(--qui-FC-B5);
  }

  /deep/ input .input-placeholder {
    font-size: $fg-f5;
    color: --color(--qui-FC-AAA);
  }

  .cell-item-right-text {
    /deep/ .cell-item__body__right-text {
      color: --color(--qui-RED);
    }
  }

  /deep/ .cell-item__body__right .cell-item__body__right-text {
    font-size: $fg-f5;
  }

  /deep/ .cell-item__body__content-title {
    color: --color(--qui-FC-777);
  }

  /deep/ .uni-list-cell {
    display: flex;
    justify-content: space-between;
    height: 100rpx;
    align-items: center;
    font-size: $fg-f4;
    color: --color(--qui-FC-777);
    border-bottom: 2rpx solid #ededed;
  }

  /deep/ .my-profile__avatar {
    position: relative;
  }

  // /deep/ .avatar-box {
  //   padding-left: 0;
  // }
  /deep/ .avatar-box__r__tit {
    color: --color(--qui-FC-TAG);
  }

  /deep/ .uni-list-cell .uni-list-cell-pd {
    position: relative;
  }

  .popup-dialog {
    width: 670rpx;
    height: 342rpx;
    background-color: --color(--qui-BG-2);
    border-radius: 14rpx;

    &__top {
      padding-top: 40rpx;
      text-align: center;

      text {
        font-size: $fg-f4;
        color: --color(--qui-FC-333);
      }
    }

    &__cont {
      position: relative;
      display: flex;
      align-items: center;
      padding: 24rpx 52rpx 40rpx;

      &-rmb {
        position: absolute;
        margin-left: 25rpx;
      }

      &-input {
        width: 100%;
        height: 100rpx;
        padding: 0 25rpx 0 80rpx;
        font-size: 40rpx;
        text-align: right;
        border: 1px solid --color(--qui-BOR-DDD);
        border-radius: 7rpx;
        box-sizing: border-box;
      }
    }

    &__ft {
      display: flex;
      align-items: center;
      height: 100rpx;
      border-top: 2rpx solid --color(--qui-BOR-DDD);
      box-sizing: border-box;

      button {
        width: 50%;
        margin: 20rpx;
        color: --color(--qui-FC-777);
        background-color: --color(--qui-BG-2);
        border-radius: 0;

        &:after {
          border: none;
        }

        &:last-of-type {
          border-left: 2rpx solid --color(--qui-BOR-DDD);
          border-bottom-right-radius: 10rpx;
        }

        &:first-of-type {
          border-bottom-left-radius: 10rpx;
        }
      }

      .popup-btn--ok--blue {
        color: --color(--qui-BG-HIGH-LIGHT);
      }
    }
  }

  /deep/ .uni-video-cover {
    display: none;
  }

  /deep/ .cell-item__body__right {
    display: contents;
  }

  .markdown-box {
    display: flex;
    flex-direction: row;
    justify-content: space-around;
    width: 100%;
    height: 60rpx;
    line-height: 60rpx;
    background: --color(--qui-BG-FFF);
    border-top: 1px solid --color(--qui-BOR-DDD);
  }

  .username {
    max-width: 200rpx;
    overflow: hidden;
    font-size: $fg-f3;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .pay-type {
    font-size: $fg-f4;
    line-height: 100rpx;
    text-align: center;
    border-bottom: 1px solid --color(--qui-BOR-ED);
  }

  .watchpay {
    font-size: $fg-f3;
    color: --color(--qui-FC-AAA);
  }

  .bottom_button {
    display: flex;
    justify-content: space-between;
    text-align: center;
  }

  .bottom_button /deep/ .qui-button--button:after {
    border: none;
  }

  .post-box__img {
    //二级下拉的样式
    position: relative;
    padding: 20rpx 10rpx;
    background-color: #f4f4f4;

    /deep/ .qui-button--button {
      background-color: #fff;
      margin: 10rpx;
      // &:hover {
      //   background: #ea3d5a;
      //   color: #ffffff;
      // }
    }

    .pullDown_img {
      position: absolute;
      top: -30rpx;
      left: 20rpx;
      width: 44rpx;
      height: 33rpx;
    }
  }

  .post-box__zhuti {
    margin-bottom: 114rpx;

    /deep/ .cell-item__body__right-text {
      font-family: 'PingFang SC';
      font-size: 28rpx;
      font-weight: 400;
      color: #000;
    }
  }

  .redshowstyle {
    &_redmargin {
      font-weight: 600;
      color: #c20c0c;
    }

    &_redelse {
      font-weight: 600;
      color: #333;
    }
  }

  .button {
    margin: 20rpx;
  }

  .post-box__position {
    position: static;
  }
</style>
